Spaces:
Sleeping
Sleeping
research14
commited on
Commit
•
e054870
1
Parent(s):
3bea5f3
testing key secret
Browse files
app.py
CHANGED
@@ -37,11 +37,8 @@ def linguistic_features_fn(message):
|
|
37 |
|
38 |
return formatted_output
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
global api_key
|
43 |
-
os.environ['OPENAI_API_TOKEN'] = new_key
|
44 |
-
openai.api_key = os.environ['OPENAI_API_TOKEN']
|
45 |
|
46 |
def chat(user_prompt, model = 'gpt-3.5-turbo', temperature = 0, verbose = False):
|
47 |
''' Normal call of OpenAI API '''
|
@@ -68,9 +65,9 @@ def format_chat_prompt(message, chat_history, max_convo_length):
|
|
68 |
prompt = f"{prompt}\nUser: {message}\nAssistant:"
|
69 |
return prompt
|
70 |
|
71 |
-
def gpt_respond(
|
72 |
-
if (have_key == "No"):
|
73 |
-
|
74 |
|
75 |
formatted_prompt = format_chat_prompt(message, chat_history, max_convo_length)
|
76 |
print('GPT ling ents Prompt + Context:')
|
@@ -112,9 +109,9 @@ def llama_respond(tab_name, message, chat_history):
|
|
112 |
time.sleep(2)
|
113 |
return tab_name, "", chat_history
|
114 |
|
115 |
-
def gpt_strategies_respond(
|
116 |
-
if (have_key == "No"):
|
117 |
-
|
118 |
|
119 |
formatted_system_prompt = ""
|
120 |
if (task_name == "POS Tagging"):
|
@@ -246,10 +243,10 @@ def interface():
|
|
246 |
|
247 |
# Inputs
|
248 |
ling_ents_prompt = gr.Textbox(show_label=False, placeholder="Write a prompt here")
|
249 |
-
with gr.Row():
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
linguistic_entities = gr.Dropdown(["Noun", "Determiner", "Noun phrase", "Verb phrase", "Dependent clause", "T-units"], label="Linguistic Entity", allow_custom_value=True, info="If your choice is not included in the options, please type your own.")
|
254 |
ling_ents_btn = gr.Button(value="Submit")
|
255 |
|
@@ -266,7 +263,7 @@ def interface():
|
|
266 |
# vicuna_ling_ents_chatbot, llama_ling_ents_chatbot, gpt_ling_ents_chatbot,])
|
267 |
|
268 |
# Event Handler for API Key
|
269 |
-
ling_ents_btn.click(update_api_key, inputs=ling_ents_apikey_input)
|
270 |
|
271 |
def update_textbox(prompt):
|
272 |
return prompt
|
@@ -277,7 +274,7 @@ def interface():
|
|
277 |
ling_ents_btn.click(linguistic_features_fn, inputs=[ling_ents_prompt], outputs=[linguistic_features_textbox])
|
278 |
|
279 |
# Event Handler for GPT 3.5 Chatbot
|
280 |
-
ling_ents_btn.click(gpt_respond, inputs=[
|
281 |
outputs=[ling_ents_prompt, gpt_ling_ents_chatbot])
|
282 |
|
283 |
# Event Handler for LLaMA Chatbot
|
@@ -331,9 +328,9 @@ def interface():
|
|
331 |
|
332 |
# Inputs
|
333 |
task_prompt = gr.Textbox(show_label=False, placeholder="Write a prompt here")
|
334 |
-
with gr.Row():
|
335 |
-
|
336 |
-
|
337 |
task = gr.Dropdown(["POS Tagging", "Chunking"], label="Task")
|
338 |
task_linguistic_entities = gr.Dropdown(["Noun", "Determiner", "Noun phrase", "Verb phrase", "Dependent clause", "T-units"], label="Linguistic Entity For Strategy 1", allow_custom_value=True, info="If your choice is not included in the options, please type your own.")
|
339 |
task_btn = gr.Button(value="Submit")
|
@@ -366,7 +363,7 @@ def interface():
|
|
366 |
# vicuna_S3_chatbot, llama_S3_chatbot, gpt_S3_chatbot])
|
367 |
|
368 |
# Event Handler for API Key
|
369 |
-
task_btn.click(update_api_key, inputs=task_apikey_input)
|
370 |
|
371 |
# Show user's original prompt
|
372 |
def update_textbox(prompt):
|
@@ -380,11 +377,11 @@ def interface():
|
|
380 |
# Event Handler for GPT 3.5 Chatbot POS/Chunk, user must submit api key before submitting the prompt
|
381 |
# Will activate after getting API key
|
382 |
# task_apikey_btn.click(update_api_key, inputs=ling_ents_apikey_input)
|
383 |
-
task_btn.click(gpt_strategies_respond, inputs=[
|
384 |
outputs=[task_prompt, gpt_S1_chatbot])
|
385 |
-
task_btn.click(gpt_strategies_respond, inputs=[
|
386 |
outputs=[task_prompt, gpt_S2_chatbot])
|
387 |
-
task_btn.click(gpt_strategies_respond, inputs=[
|
388 |
outputs=[task_prompt, gpt_S3_chatbot])
|
389 |
|
390 |
# Event Handler for LLaMA Chatbot POS/Chunk
|
|
|
37 |
|
38 |
return formatted_output
|
39 |
|
40 |
+
os.environ['OPENAI_API_TOKEN'] = OPENAI_API_KEY
|
41 |
+
openai.api_key = os.environ['OPENAI_API_TOKEN']
|
|
|
|
|
|
|
42 |
|
43 |
def chat(user_prompt, model = 'gpt-3.5-turbo', temperature = 0, verbose = False):
|
44 |
''' Normal call of OpenAI API '''
|
|
|
65 |
prompt = f"{prompt}\nUser: {message}\nAssistant:"
|
66 |
return prompt
|
67 |
|
68 |
+
def gpt_respond(tab_name, message, chat_history, max_convo_length = 10):
|
69 |
+
# if (have_key == "No"):
|
70 |
+
# return "", chat_history
|
71 |
|
72 |
formatted_prompt = format_chat_prompt(message, chat_history, max_convo_length)
|
73 |
print('GPT ling ents Prompt + Context:')
|
|
|
109 |
time.sleep(2)
|
110 |
return tab_name, "", chat_history
|
111 |
|
112 |
+
def gpt_strategies_respond(strategy, task_name, task_ling_ent, message, chat_history, max_convo_length = 10):
|
113 |
+
# if (have_key == "No"):
|
114 |
+
# return "", chat_history
|
115 |
|
116 |
formatted_system_prompt = ""
|
117 |
if (task_name == "POS Tagging"):
|
|
|
243 |
|
244 |
# Inputs
|
245 |
ling_ents_prompt = gr.Textbox(show_label=False, placeholder="Write a prompt here")
|
246 |
+
# with gr.Row():
|
247 |
+
# # Will activate after getting API key
|
248 |
+
# have_key2 = gr.Dropdown(["Yes", "No"], label="Do you own an API Key?", scale=0.5)
|
249 |
+
# ling_ents_apikey_input = gr.Textbox(label="Open AI Key", placeholder="Enter your OpenAI key here", type="password")
|
250 |
linguistic_entities = gr.Dropdown(["Noun", "Determiner", "Noun phrase", "Verb phrase", "Dependent clause", "T-units"], label="Linguistic Entity", allow_custom_value=True, info="If your choice is not included in the options, please type your own.")
|
251 |
ling_ents_btn = gr.Button(value="Submit")
|
252 |
|
|
|
263 |
# vicuna_ling_ents_chatbot, llama_ling_ents_chatbot, gpt_ling_ents_chatbot,])
|
264 |
|
265 |
# Event Handler for API Key
|
266 |
+
# ling_ents_btn.click(update_api_key, inputs=ling_ents_apikey_input)
|
267 |
|
268 |
def update_textbox(prompt):
|
269 |
return prompt
|
|
|
274 |
ling_ents_btn.click(linguistic_features_fn, inputs=[ling_ents_prompt], outputs=[linguistic_features_textbox])
|
275 |
|
276 |
# Event Handler for GPT 3.5 Chatbot
|
277 |
+
ling_ents_btn.click(gpt_respond, inputs=[linguistic_entities, ling_ents_prompt, gpt_ling_ents_chatbot],
|
278 |
outputs=[ling_ents_prompt, gpt_ling_ents_chatbot])
|
279 |
|
280 |
# Event Handler for LLaMA Chatbot
|
|
|
328 |
|
329 |
# Inputs
|
330 |
task_prompt = gr.Textbox(show_label=False, placeholder="Write a prompt here")
|
331 |
+
# with gr.Row():
|
332 |
+
# have_key = gr.Dropdown(["Yes", "No"], label="Do you own an API Key?", scale=0.5)
|
333 |
+
# task_apikey_input = gr.Textbox(label="Open AI Key", placeholder="Enter your OpenAI key here", type="password", visible=True)
|
334 |
task = gr.Dropdown(["POS Tagging", "Chunking"], label="Task")
|
335 |
task_linguistic_entities = gr.Dropdown(["Noun", "Determiner", "Noun phrase", "Verb phrase", "Dependent clause", "T-units"], label="Linguistic Entity For Strategy 1", allow_custom_value=True, info="If your choice is not included in the options, please type your own.")
|
336 |
task_btn = gr.Button(value="Submit")
|
|
|
363 |
# vicuna_S3_chatbot, llama_S3_chatbot, gpt_S3_chatbot])
|
364 |
|
365 |
# Event Handler for API Key
|
366 |
+
# task_btn.click(update_api_key, inputs=task_apikey_input)
|
367 |
|
368 |
# Show user's original prompt
|
369 |
def update_textbox(prompt):
|
|
|
377 |
# Event Handler for GPT 3.5 Chatbot POS/Chunk, user must submit api key before submitting the prompt
|
378 |
# Will activate after getting API key
|
379 |
# task_apikey_btn.click(update_api_key, inputs=ling_ents_apikey_input)
|
380 |
+
task_btn.click(gpt_strategies_respond, inputs=[strategy1, task, task_linguistic_entities, task_prompt, gpt_S1_chatbot],
|
381 |
outputs=[task_prompt, gpt_S1_chatbot])
|
382 |
+
task_btn.click(gpt_strategies_respond, inputs=[strategy2, task, task_linguistic_entities, task_prompt, gpt_S2_chatbot],
|
383 |
outputs=[task_prompt, gpt_S2_chatbot])
|
384 |
+
task_btn.click(gpt_strategies_respond, inputs=[strategy3, task, task_linguistic_entities, task_prompt, gpt_S3_chatbot],
|
385 |
outputs=[task_prompt, gpt_S3_chatbot])
|
386 |
|
387 |
# Event Handler for LLaMA Chatbot POS/Chunk
|