CCCCCC commited on
Commit
7671053
·
1 Parent(s): b09d966

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -4
app.py CHANGED
@@ -10,9 +10,27 @@ model_path = 'THUDM/BPO'
10
 
11
  device = 'cuda'
12
 
13
- tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True, add_prefix_space=True)
14
- model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True, load_in_8bit=True)
15
- model = model.eval()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  prompt_template = "[INST] You are an expert prompt engineer. Please help me improve this prompt to get a more helpful and harmless response:\n{} [/INST]"
18
 
@@ -119,9 +137,13 @@ def reset_state():
119
  def update_textbox_from_dropdown(selected_example):
120
  return selected_example
121
 
122
- with gr.Blocks() as demo:
123
  gr.HTML("""<h1 align="center">Prompt Preference Optimizer</h1>""")
124
 
 
 
 
 
125
  chatbot = gr.Chatbot(label="Prompt Optimization Chatbot")
126
  with gr.Row():
127
  with gr.Column(scale=4):
@@ -137,6 +159,8 @@ with gr.Blocks() as demo:
137
  top_p = gr.Slider(0, 1, value=0.9, step=0.01, label="Top P", interactive=True)
138
  temperature = gr.Slider(0, 1, value=0.6, step=0.01, label="Temperature", interactive=True)
139
 
 
 
140
  dropdown.change(update_textbox_from_dropdown, dropdown, user_input)
141
 
142
  history = gr.State([])
 
10
 
11
  device = 'cuda'
12
 
13
+ if torch.cuda.is_available():
14
+
15
+ tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True, add_prefix_space=True)
16
+ model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True, device_map=device, load_in_8bit=True)
17
+ model = model.eval()
18
+
19
+
20
+ DESCRIPTION = """This Space demonstrates model [BPO](https://huggingface.co/THUDM/BPO), which is built on LLaMA-2-7b-chat.
21
+ BPO aims to improve the alignment of LLMs with human preferences by optimizing user prompts.
22
+
23
+ Feel free to play with it, or duplicate to run generations without a queue! 🔎 For more details about the BPO model, take a look [at our paper](https://arxiv.org/pdf/2311.04155.pdf).
24
+ """
25
+
26
+ LICENSE = """
27
+ ---
28
+ As BPO is a fine-tuned version of [Llama-2-7b-chat](https://huggingface.co/meta-llama/Llama-2-7b-chat) by Meta,
29
+ this demo is governed by the original [license](https://huggingface.co/spaces/CCCCCC/BPO_demo/blob/main/LICENSE.txt) and [acceptable use policy](https://huggingface.co/spaces/CCCCCC/BPO_demo/blob/main/USE_POLICY.md).
30
+ """
31
+
32
+ if not torch.cuda.is_available():
33
+ DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
34
 
35
  prompt_template = "[INST] You are an expert prompt engineer. Please help me improve this prompt to get a more helpful and harmless response:\n{} [/INST]"
36
 
 
137
  def update_textbox_from_dropdown(selected_example):
138
  return selected_example
139
 
140
+ with gr.Blocks("sty.css") as demo:
141
  gr.HTML("""<h1 align="center">Prompt Preference Optimizer</h1>""")
142
 
143
+ gr.Markdown(DESCRIPTION)
144
+
145
+ gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
146
+
147
  chatbot = gr.Chatbot(label="Prompt Optimization Chatbot")
148
  with gr.Row():
149
  with gr.Column(scale=4):
 
159
  top_p = gr.Slider(0, 1, value=0.9, step=0.01, label="Top P", interactive=True)
160
  temperature = gr.Slider(0, 1, value=0.6, step=0.01, label="Temperature", interactive=True)
161
 
162
+ gr.Markdown(LICENSE)
163
+
164
  dropdown.change(update_textbox_from_dropdown, dropdown, user_input)
165
 
166
  history = gr.State([])