Nina commited on
Commit
871aa55
β€’
1 Parent(s): 0b632f4

change user id

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -48,6 +48,7 @@ account_url = os.environ["account_url"]
48
  file_share_name = "climategpt"
49
  service = ShareServiceClient(account_url=account_url, credential=credential)
50
  share_client = service.get_share_client(file_share_name)
 
51
 
52
 
53
  def chat(
@@ -86,7 +87,9 @@ def chat(
86
  )
87
 
88
  if sources:
89
- messages.append({"role": "system", "content": f"{os.environ['sources']}\n\n{sources}"})
 
 
90
 
91
  response = openai.Completion.create(
92
  engine="climateGPT",
@@ -101,9 +104,7 @@ def chat(
101
  messages.pop()
102
  else:
103
  sources = "No environmental report was used to provide this answer."
104
- complete_response = (
105
- "No relevant documents found, for a sourced answer you may want to try a more specific question.\n\n"
106
- )
107
 
108
  messages.append({"role": "assistant", "content": complete_response})
109
  timestamp = str(datetime.now().timestamp())
@@ -120,7 +121,9 @@ def chat(
120
  log_on_azure(file, logs, share_client)
121
 
122
  for chunk in response:
123
- if (chunk_message := chunk["choices"][0].get("text")) and chunk_message != "<|im_end|>":
 
 
124
  complete_response += chunk_message
125
  messages[-1]["content"] = complete_response
126
  gradio_format = make_pairs([a["content"] for a in messages[1:]])
@@ -152,7 +155,6 @@ def log_on_azure(file, logs, share_client):
152
  # Gradio
153
  css_code = ".gradio-container {background-image: url('file=background.png');background-position: top right}"
154
  with gr.Blocks(title="🌍 ClimateGPT Ekimetrics", css=css_code) as demo:
155
- user_id = create_user_id(10)
156
  user_id_state = gr.State([user_id])
157
 
158
  with gr.Tab("App"):
@@ -178,7 +180,9 @@ with gr.Blocks(title="🌍 ClimateGPT Ekimetrics", css=css_code) as demo:
178
 
179
  with gr.Column(scale=1, variant="panel"):
180
  gr.Markdown("### Sources")
181
- sources_textbox = gr.Textbox(interactive=False, show_label=False, max_lines=50)
 
 
182
  ask.submit(
183
  fn=chat,
184
  inputs=[
@@ -212,8 +216,12 @@ with gr.Blocks(title="🌍 ClimateGPT Ekimetrics", css=css_code) as demo:
212
  lines=1,
213
  type="password",
214
  )
215
- openai_api_key_textbox.change(set_openai_api_key, inputs=[openai_api_key_textbox])
216
- openai_api_key_textbox.submit(set_openai_api_key, inputs=[openai_api_key_textbox])
 
 
 
 
217
 
218
  with gr.Tab("Information"):
219
  gr.Markdown(
 
48
  file_share_name = "climategpt"
49
  service = ShareServiceClient(account_url=account_url, credential=credential)
50
  share_client = service.get_share_client(file_share_name)
51
+ user_id = create_user_id(10)
52
 
53
 
54
  def chat(
 
87
  )
88
 
89
  if sources:
90
+ messages.append(
91
+ {"role": "system", "content": f"{os.environ['sources']}\n\n{sources}"}
92
+ )
93
 
94
  response = openai.Completion.create(
95
  engine="climateGPT",
 
104
  messages.pop()
105
  else:
106
  sources = "No environmental report was used to provide this answer."
107
+ complete_response = "No relevant documents found, for a sourced answer you may want to try a more specific question.\n\n"
 
 
108
 
109
  messages.append({"role": "assistant", "content": complete_response})
110
  timestamp = str(datetime.now().timestamp())
 
121
  log_on_azure(file, logs, share_client)
122
 
123
  for chunk in response:
124
+ if (
125
+ chunk_message := chunk["choices"][0].get("text")
126
+ ) and chunk_message != "<|im_end|>":
127
  complete_response += chunk_message
128
  messages[-1]["content"] = complete_response
129
  gradio_format = make_pairs([a["content"] for a in messages[1:]])
 
155
  # Gradio
156
  css_code = ".gradio-container {background-image: url('file=background.png');background-position: top right}"
157
  with gr.Blocks(title="🌍 ClimateGPT Ekimetrics", css=css_code) as demo:
 
158
  user_id_state = gr.State([user_id])
159
 
160
  with gr.Tab("App"):
 
180
 
181
  with gr.Column(scale=1, variant="panel"):
182
  gr.Markdown("### Sources")
183
+ sources_textbox = gr.Textbox(
184
+ interactive=False, show_label=False, max_lines=50
185
+ )
186
  ask.submit(
187
  fn=chat,
188
  inputs=[
 
216
  lines=1,
217
  type="password",
218
  )
219
+ openai_api_key_textbox.change(
220
+ set_openai_api_key, inputs=[openai_api_key_textbox]
221
+ )
222
+ openai_api_key_textbox.submit(
223
+ set_openai_api_key, inputs=[openai_api_key_textbox]
224
+ )
225
 
226
  with gr.Tab("Information"):
227
  gr.Markdown(