research14 commited on
Commit
1941971
1 Parent(s): 13d157d
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -11,7 +11,10 @@ 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
- global api_key
 
 
 
15
 
16
  def chat(system_prompt, user_prompt, model = 'gpt-3.5-turbo', temperature = 0, verbose = False):
17
  ''' Normal call of OpenAI API '''
@@ -62,13 +65,11 @@ def interface():
62
  gr.Markdown(" Description ")
63
 
64
  textbox_prompt = gr.Textbox(show_label=False, placeholder="Write a prompt and press enter")
65
- api_key_input = gr.Textbox(label="Open AI Key", placeholder="Enter your Openai key here", type="password")
 
 
66
  tab_name = gr.Dropdown(["Noun", "Determiner", "Noun phrase", "Verb phrase", "Dependent clause", "T-units"], label="Linguistic Entity")
67
- btn = gr.Button("Submit")
68
-
69
- #API Keys
70
- os.environ['OPENAI_API_TOKEN'] = api_key_input.value
71
- openai.api_key = os.environ['OPENAI_API_TOKEN']
72
 
73
  # prompt = template_single.format(tab_name, textbox_prompt)
74
 
@@ -95,6 +96,7 @@ def interface():
95
  textbox_prompt.submit(respond, inputs=[textbox_prompt, vicuna_S2_chatbot], outputs=[textbox_prompt, vicuna_S2_chatbot])
96
  textbox_prompt.submit(respond, inputs=[textbox_prompt, vicuna_S3_chatbot], outputs=[textbox_prompt, vicuna_S3_chatbot])
97
 
 
98
  btn.click(respond_gpt, inputs=[tab_name, textbox_prompt, gpt_S1_chatbot], outputs=[tab_name, textbox_prompt, gpt_S1_chatbot])
99
 
100
  with gr.Blocks() as demo:
 
11
 
12
  template_single = '''Please output any <{}> in the following sentence one per line without any additional text: "{}"'''
13
 
14
+ def update_api_key(new_key):
15
+ global api_key
16
+ os.environ['OPENAI_API_TOKEN'] = new_key.value
17
+ openai.api_key = os.environ['OPENAI_API_TOKEN']
18
 
19
  def chat(system_prompt, user_prompt, model = 'gpt-3.5-turbo', temperature = 0, verbose = False):
20
  ''' Normal call of OpenAI API '''
 
65
  gr.Markdown(" Description ")
66
 
67
  textbox_prompt = gr.Textbox(show_label=False, placeholder="Write a prompt and press enter")
68
+ with gr.Row():
69
+ api_key_input = gr.Textbox(label="Open AI Key", placeholder="Enter your Openai key here", type="password")
70
+ api_key_btn = gr.Button(label="Submit Api Key", scale=0)
71
  tab_name = gr.Dropdown(["Noun", "Determiner", "Noun phrase", "Verb phrase", "Dependent clause", "T-units"], label="Linguistic Entity")
72
+ btn = gr.Button(label="Submit")
 
 
 
 
73
 
74
  # prompt = template_single.format(tab_name, textbox_prompt)
75
 
 
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(respond_gpt, inputs=[tab_name, textbox_prompt, gpt_S1_chatbot], outputs=[tab_name, textbox_prompt, gpt_S1_chatbot])
101
 
102
  with gr.Blocks() as demo: