Spaces:
Runtime error
Runtime error
Commit
·
8c76c4e
1
Parent(s):
75d229a
test
Browse files
app.py
CHANGED
|
@@ -11,9 +11,12 @@ model = AutoModelForCausalLM.from_pretrained(model_name)
|
|
| 11 |
|
| 12 |
template_single = '''Please output any <{}> in the following sentence one per line without any additional text: "{}"'''
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
def chat(system_prompt, user_prompt, model = 'gpt-3.5-turbo', temperature = 0, verbose = False):
|
| 19 |
''' Normal call of OpenAI API '''
|
|
@@ -51,6 +54,11 @@ def respond_gpt(tab_name, message, chat_history, max_convo_length = 10):
|
|
| 51 |
chat_history.append((message, bot_message))
|
| 52 |
return "", chat_history
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
def respond(message, chat_history):
|
| 55 |
input_ids = tokenizer.encode(message, return_tensors="pt")
|
| 56 |
output_ids = model.generate(input_ids, max_length=50, num_beams=5, no_repeat_ngram_size=2)
|
|
@@ -64,13 +72,12 @@ def interface():
|
|
| 64 |
gr.Markdown(" Description ")
|
| 65 |
|
| 66 |
textbox_prompt = gr.Textbox(show_label=False, placeholder="Write a prompt and press enter")
|
| 67 |
-
|
|
|
|
| 68 |
btn = gr.Button("Submit")
|
| 69 |
|
| 70 |
# prompt = template_single.format(tab_name, textbox_prompt)
|
| 71 |
|
| 72 |
-
tab_name = gr.Dropdown(["Noun", "Determiner", "Noun phrase", "Verb phrase", "Dependent clause", "T-units"], label="Linguistic Entity")
|
| 73 |
-
|
| 74 |
gr.Markdown("Strategy 1 QA-Based Prompting")
|
| 75 |
with gr.Row():
|
| 76 |
vicuna_S1_chatbot = gr.Chatbot(label="vicuna-7b")
|
|
@@ -94,7 +101,10 @@ def interface():
|
|
| 94 |
textbox_prompt.submit(respond, inputs=[textbox_prompt, vicuna_S2_chatbot], outputs=[textbox_prompt, vicuna_S2_chatbot])
|
| 95 |
textbox_prompt.submit(respond, inputs=[textbox_prompt, vicuna_S3_chatbot], outputs=[textbox_prompt, vicuna_S3_chatbot])
|
| 96 |
|
| 97 |
-
btn.click(
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
with gr.Blocks() as demo:
|
| 100 |
gr.Markdown("# LLM Evaluator With Linguistic Scrutiny")
|
|
|
|
| 11 |
|
| 12 |
template_single = '''Please output any <{}> in the following sentence one per line without any additional text: "{}"'''
|
| 13 |
|
| 14 |
+
api_key = ""
|
| 15 |
+
|
| 16 |
+
def set_api_key(new_api_key):
|
| 17 |
+
global api_key
|
| 18 |
+
api_key = new_api_key
|
| 19 |
+
os.environ['OPENAI_API_TOKEN'] = api_key
|
| 20 |
|
| 21 |
def chat(system_prompt, user_prompt, model = 'gpt-3.5-turbo', temperature = 0, verbose = False):
|
| 22 |
''' Normal call of OpenAI API '''
|
|
|
|
| 54 |
chat_history.append((message, bot_message))
|
| 55 |
return "", chat_history
|
| 56 |
|
| 57 |
+
def set_api_key_and_submit(api_key_input, textbox_prompt, vicuna_chatbot):
|
| 58 |
+
set_api_key(api_key_input)
|
| 59 |
+
textbox_prompt.submit(respond, inputs=[textbox_prompt, vicuna_chatbot], outputs=[textbox_prompt, vicuna_chatbot])
|
| 60 |
+
|
| 61 |
+
|
| 62 |
def respond(message, chat_history):
|
| 63 |
input_ids = tokenizer.encode(message, return_tensors="pt")
|
| 64 |
output_ids = model.generate(input_ids, max_length=50, num_beams=5, no_repeat_ngram_size=2)
|
|
|
|
| 72 |
gr.Markdown(" Description ")
|
| 73 |
|
| 74 |
textbox_prompt = gr.Textbox(show_label=False, placeholder="Write a prompt and press enter")
|
| 75 |
+
api_key_input = gr.Textbox(label="Open AI Key", placeholder="Enter your Openai key here", type="password")
|
| 76 |
+
tab_name = gr.Dropdown(["Noun", "Determiner", "Noun phrase", "Verb phrase", "Dependent clause", "T-units"], label="Linguistic Entity")
|
| 77 |
btn = gr.Button("Submit")
|
| 78 |
|
| 79 |
# prompt = template_single.format(tab_name, textbox_prompt)
|
| 80 |
|
|
|
|
|
|
|
| 81 |
gr.Markdown("Strategy 1 QA-Based Prompting")
|
| 82 |
with gr.Row():
|
| 83 |
vicuna_S1_chatbot = gr.Chatbot(label="vicuna-7b")
|
|
|
|
| 101 |
textbox_prompt.submit(respond, inputs=[textbox_prompt, vicuna_S2_chatbot], outputs=[textbox_prompt, vicuna_S2_chatbot])
|
| 102 |
textbox_prompt.submit(respond, inputs=[textbox_prompt, vicuna_S3_chatbot], outputs=[textbox_prompt, vicuna_S3_chatbot])
|
| 103 |
|
| 104 |
+
btn.click(set_api_key_and_submit, inputs=[api_key_input, textbox_prompt, vicuna_S1_chatbot],
|
| 105 |
+
outputs=[api_key_input, textbox_prompt, vicuna_S1_chatbot])
|
| 106 |
+
|
| 107 |
+
gr.Widget([textbox_prompt, api_key_input, tab_name, btn])
|
| 108 |
|
| 109 |
with gr.Blocks() as demo:
|
| 110 |
gr.Markdown("# LLM Evaluator With Linguistic Scrutiny")
|