Spaces:
Runtime error
Runtime error
Commit
·
94f53fc
1
Parent(s):
6204d1b
test
Browse files
app.py
CHANGED
@@ -4,10 +4,13 @@ import time
|
|
4 |
import os
|
5 |
import openai
|
6 |
|
7 |
-
# Load the Vicuna 7B
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
11 |
|
12 |
template_single = '''Please output any <{}> in the following sentence one per line without any additional text: "{}"'''
|
13 |
|
@@ -43,7 +46,7 @@ def format_chat_prompt(message, chat_history, max_convo_length):
|
|
43 |
prompt = f"{prompt}\nUser: {message}\nAssistant:"
|
44 |
return prompt
|
45 |
|
46 |
-
def
|
47 |
formatted_prompt = format_chat_prompt(message, chat_history, max_convo_length)
|
48 |
print('Prompt + Context:')
|
49 |
print(formatted_prompt)
|
@@ -52,10 +55,28 @@ def respond_gpt(tab_name, message, chat_history, max_convo_length = 10):
|
|
52 |
chat_history.append((message, bot_message))
|
53 |
return "", chat_history
|
54 |
|
55 |
-
def
|
56 |
-
input_ids =
|
57 |
-
output_ids =
|
58 |
-
bot_message =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
chat_history.append((message, bot_message))
|
61 |
time.sleep(2)
|
@@ -78,68 +99,32 @@ def interface():
|
|
78 |
vicuna_S1_chatbot = gr.Chatbot(label="vicuna-7b")
|
79 |
llama_S1_chatbot = gr.Chatbot(label="llama-7b")
|
80 |
gpt_S1_chatbot = gr.Chatbot(label="gpt-3.5")
|
81 |
-
clear = gr.ClearButton(components=[textbox_prompt, vicuna_S1_chatbot])
|
82 |
-
gr.Markdown("Strategy 2 Instruction-Based Prompting")
|
83 |
-
with gr.Row():
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
clear = gr.ClearButton(components=[textbox_prompt, vicuna_S2_chatbot])
|
88 |
-
gr.Markdown("Strategy 3 Structured Prompting")
|
89 |
-
with gr.Row():
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
clear = gr.ClearButton(components=[textbox_prompt, vicuna_S3_chatbot])
|
94 |
-
|
95 |
-
textbox_prompt.submit(
|
96 |
-
textbox_prompt.submit(respond, inputs=[textbox_prompt, vicuna_S2_chatbot], outputs=[textbox_prompt, vicuna_S2_chatbot])
|
97 |
-
textbox_prompt.submit(respond, inputs=[textbox_prompt, vicuna_S3_chatbot], outputs=[textbox_prompt, vicuna_S3_chatbot])
|
|
|
|
|
98 |
|
99 |
api_key_btn.click(update_api_key, inputs=api_key_input)
|
100 |
-
btn.click(
|
101 |
|
102 |
with gr.Blocks() as demo:
|
103 |
gr.Markdown("# LLM Evaluator With Linguistic Scrutiny")
|
104 |
|
105 |
-
|
106 |
-
interface()
|
107 |
|
108 |
-
with gr.Tab("Determiner"):
|
109 |
-
gr.Markdown(" Description ")
|
110 |
-
|
111 |
-
prompt_CHUNK = gr.Textbox(show_label=False, placeholder="Write a prompt and press enter")
|
112 |
-
|
113 |
-
gr.Markdown("Strategy 1 QA")
|
114 |
-
with gr.Row():
|
115 |
-
vicuna_S1_chatbot_CHUNK = gr.Chatbot(label="vicuna-7b")
|
116 |
-
llama_S1_chatbot_CHUNK = gr.Chatbot(label="llama-7b")
|
117 |
-
gpt_S1_chatbot_CHUNK = gr.Chatbot(label="gpt-3.5")
|
118 |
-
clear = gr.ClearButton([prompt_CHUNK, vicuna_S1_chatbot_CHUNK])
|
119 |
-
gr.Markdown("Strategy 2 Instruction")
|
120 |
-
with gr.Row():
|
121 |
-
vicuna_S2_chatbot_CHUNK = gr.Chatbot(label="vicuna-7b")
|
122 |
-
llama_S2_chatbot_CHUNK = gr.Chatbot(label="llama-7b")
|
123 |
-
gpt_S2_chatbot_CHUNK = gr.Chatbot(label="gpt-3.5")
|
124 |
-
clear = gr.ClearButton([prompt_CHUNK, vicuna_S2_chatbot_CHUNK])
|
125 |
-
gr.Markdown("Strategy 3 Structured Prompting")
|
126 |
-
with gr.Row():
|
127 |
-
vicuna_S3_chatbot_CHUNK = gr.Chatbot(label="vicuna-7b")
|
128 |
-
llama_S3_chatbot_CHUNK = gr.Chatbot(label="llama-7b")
|
129 |
-
gpt_S3_chatbot_CHUNK = gr.Chatbot(label="gpt-3.5")
|
130 |
-
clear = gr.ClearButton([prompt_CHUNK, vicuna_S3_chatbot_CHUNK])
|
131 |
-
|
132 |
-
with gr.Tab("Noun phrase"):
|
133 |
-
interface()
|
134 |
-
with gr.Tab("Verb phrase"):
|
135 |
-
interface()
|
136 |
-
with gr.Tab("Dependent clause"):
|
137 |
-
interface()
|
138 |
-
with gr.Tab("T-units"):
|
139 |
-
interface()
|
140 |
-
|
141 |
-
prompt_CHUNK.submit(respond, [prompt_CHUNK, vicuna_S1_chatbot_CHUNK], [prompt_CHUNK, vicuna_S1_chatbot_CHUNK])
|
142 |
-
prompt_CHUNK.submit(respond, [prompt_CHUNK, vicuna_S2_chatbot_CHUNK], [prompt_CHUNK, vicuna_S2_chatbot_CHUNK])
|
143 |
-
prompt_CHUNK.submit(respond, [prompt_CHUNK, vicuna_S3_chatbot_CHUNK], [prompt_CHUNK, vicuna_S3_chatbot_CHUNK])
|
144 |
-
|
145 |
demo.launch()
|
|
|
4 |
import os
|
5 |
import openai
|
6 |
|
7 |
+
# Load the Vicuna 7B model and tokenizer
|
8 |
+
vicuna_tokenizer = AutoTokenizer.from_pretrained("lmsys/vicuna-7b-v1.3")
|
9 |
+
vicuna_model = AutoModelForCausalLM.from_pretrained("lmsys/vicuna-7b-v1.3")
|
10 |
+
|
11 |
+
# Load the LLaMA 7b model and tokenizer
|
12 |
+
llama_tokenizer = AutoTokenizer.from_pretrained("luodian/llama-7b-hf")
|
13 |
+
llama_model = AutoModelForCausalLM.from_pretrained("luodian/llama-7b-hf")
|
14 |
|
15 |
template_single = '''Please output any <{}> in the following sentence one per line without any additional text: "{}"'''
|
16 |
|
|
|
46 |
prompt = f"{prompt}\nUser: {message}\nAssistant:"
|
47 |
return prompt
|
48 |
|
49 |
+
def gpt_respond(tab_name, message, chat_history, max_convo_length = 10):
|
50 |
formatted_prompt = format_chat_prompt(message, chat_history, max_convo_length)
|
51 |
print('Prompt + Context:')
|
52 |
print(formatted_prompt)
|
|
|
55 |
chat_history.append((message, bot_message))
|
56 |
return "", chat_history
|
57 |
|
58 |
+
def vicuna_respond(message, chat_history):
|
59 |
+
input_ids = vicuna_tokenizer.encode(message, return_tensors="pt")
|
60 |
+
output_ids = vicuna_model.generate(input_ids, max_length=50, num_beams=5, no_repeat_ngram_size=2)
|
61 |
+
bot_message = vicuna_tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
62 |
+
|
63 |
+
chat_history.append((message, bot_message))
|
64 |
+
time.sleep(2)
|
65 |
+
return "", chat_history
|
66 |
+
|
67 |
+
def llama_respond(message, chat_history):
|
68 |
+
input_ids = llama_tokenizer.encode(message, return_tensors="pt")
|
69 |
+
output_ids = llama_model.generate(input_ids, max_length=50, num_beams=5, no_repeat_ngram_size=2)
|
70 |
+
bot_message = llama_tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
71 |
+
|
72 |
+
chat_history.append((message, bot_message))
|
73 |
+
time.sleep(2)
|
74 |
+
return "", chat_history
|
75 |
+
|
76 |
+
def vicuna_respond(message, chat_history):
|
77 |
+
input_ids = vicuna_tokenizer.encode(message, return_tensors="pt")
|
78 |
+
output_ids = vicuna_model.generate(input_ids, max_length=50, num_beams=5, no_repeat_ngram_size=2)
|
79 |
+
bot_message = vicuna_tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
80 |
|
81 |
chat_history.append((message, bot_message))
|
82 |
time.sleep(2)
|
|
|
99 |
vicuna_S1_chatbot = gr.Chatbot(label="vicuna-7b")
|
100 |
llama_S1_chatbot = gr.Chatbot(label="llama-7b")
|
101 |
gpt_S1_chatbot = gr.Chatbot(label="gpt-3.5")
|
102 |
+
clear = gr.ClearButton(components=[textbox_prompt, api_key_input, vicuna_S1_chatbot, llama_S1_chatbot, gpt_S1_chatbot])
|
103 |
+
# gr.Markdown("Strategy 2 Instruction-Based Prompting")
|
104 |
+
# with gr.Row():
|
105 |
+
# vicuna_S2_chatbot = gr.Chatbot(label="vicuna-7b")
|
106 |
+
# llama_S2_chatbot = gr.Chatbot(label="llama-7b")
|
107 |
+
# gpt_S2_chatbot = gr.Chatbot(label="gpt-3.5")
|
108 |
+
# clear = gr.ClearButton(components=[textbox_prompt, vicuna_S2_chatbot])
|
109 |
+
# gr.Markdown("Strategy 3 Structured Prompting")
|
110 |
+
# with gr.Row():
|
111 |
+
# vicuna_S3_chatbot = gr.Chatbot(label="vicuna-7b")
|
112 |
+
# llama_S3_chatbot = gr.Chatbot(label="llama-7b")
|
113 |
+
# gpt_S3_chatbot = gr.Chatbot(label="gpt-3.5")
|
114 |
+
# clear = gr.ClearButton(components=[textbox_prompt, vicuna_S3_chatbot])
|
115 |
+
|
116 |
+
textbox_prompt.submit(vicuna_respond, inputs=[textbox_prompt, vicuna_S1_chatbot], outputs=[textbox_prompt, vicuna_S1_chatbot])
|
117 |
+
# textbox_prompt.submit(respond, inputs=[textbox_prompt, vicuna_S2_chatbot], outputs=[textbox_prompt, vicuna_S2_chatbot])
|
118 |
+
# textbox_prompt.submit(respond, inputs=[textbox_prompt, vicuna_S3_chatbot], outputs=[textbox_prompt, vicuna_S3_chatbot])
|
119 |
+
|
120 |
+
textbox_prompt.submit(llama_respond, inputs=[textbox_prompt, llama_S1_chatbot], outputs=[textbox_prompt, llama_S1_chatbot])
|
121 |
|
122 |
api_key_btn.click(update_api_key, inputs=api_key_input)
|
123 |
+
btn.click(gpt_respond, inputs=[tab_name, textbox_prompt, gpt_S1_chatbot], outputs=[tab_name, textbox_prompt, gpt_S1_chatbot])
|
124 |
|
125 |
with gr.Blocks() as demo:
|
126 |
gr.Markdown("# LLM Evaluator With Linguistic Scrutiny")
|
127 |
|
128 |
+
interface()
|
|
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
demo.launch()
|