dlflannery commited on
Commit
c6a8164
·
verified ·
1 Parent(s): 0e963c9

Update app.py

Browse files

new_window appears only in news mode

Files changed (1) hide show
  1. app.py +35 -24
app.py CHANGED
@@ -62,7 +62,7 @@ abbrevs = {'St. ' : 'Saint ', 'Mr. ': 'mister ', 'Mrs. ':'mussus ', 'Mr. ':'mist
62
 
63
  special_chat_types = ['math', 'logic']
64
 
65
- news_interval_choices = [("None", "None"), ("Day", "pd"), ("Week", "pw"), ("Month", "pm"), ("Year", "py")]
66
 
67
  class Step(BaseModel):
68
  explanation: str
@@ -664,7 +664,7 @@ def new_conversation(user):
664
  os.remove(fpath)
665
  return [None, [], gr.Markdown(value='', label='Dialog', container=True),
666
  gr.Image(visible=False, value=None), gr.Image(visible=False, value=None), '',
667
- gr.LinePlot(visible=False), gr.Dropdown(value="None"), gr.Dropdown(value='Chat')]
668
 
669
  def updatePassword(txt):
670
  password = txt.lower().strip()
@@ -689,7 +689,7 @@ def updatePassword(txt):
689
  # return txt
690
 
691
  def chat(prompt, user_window, pwd_window, past, response, gptModel, uploaded_image_file='',
692
- plot=None, news_interval = 'none', mode = 'Chat'):
693
  image_gen_model = 'gpt-4o-2024-08-06'
694
  user_window = user_window.lower().strip()
695
  isBoss = False
@@ -1046,33 +1046,37 @@ def show_help():
1046
  tapping the audio "Record" button, saying your prompt, then tapping the "Stop" button.
1047
  Your prompt will appear in the Prompt window, and you can edit it there if needed.
1048
  1.3 Text in the "Dialog" window can be spoken by tapping the "Speak Dialog" button.
1049
- 2. Chat:
1050
- 2.1 Enter prompt and tap the "Submit Prompt/Question" button. The responses appear in the Dialog window.
1051
- 2.2 Enter follow-up questions in the Prompt window either by typing or speaking. Tap the voice
 
 
 
 
1052
  entry "Reset Voice Entry" button to enable additional voice entry. Then tap "Submit Prompt/Question".
1053
- 2.3 If topic changes or when done chatting, tap the "Restart Conversation" button.
1054
- 3. Solve math equations or logic problems providing step-by-step analysis:
1055
- 3.1 Math: Make "solve" the first word in your prompt, followed by the equation, e.g., x^2 - x + 1 = 0
1056
- 3.2 Logic: Make "puzzle" the first word in your prompt, followed by a detailed description of a logic
1057
  problem with the answer(s) you desire.
1058
- 4. Make Image:
1059
- 4.1 Enter description of desired image in prompt window via either typing or voice entry
1060
- 4.2 Tap the "Make Image" button. This can take a few seconds.
1061
- 4.3 There is a download button on the image display if your system supports file downloads.
1062
- 4.4 When done viewing image, tap the "Restart Conversation" button
1063
- 5. Analyze an Image you provide:
1064
- 5.1 Enter what you want to know about the image in the prompt window. You can include instructions
1065
- to write a poem about something in the image, for example. Or just say "what's in this image?"
1066
- 5.2 Tap the "Upload Image to Analyze" button.
1067
- 5.3 An empty image box will appear lower left. Drag or upload image into it. It offers web cam or camera
1068
  input also.
1069
- 5.4 The image should appear. This can take some time with a slow internet connection and large image.
1070
- 5.5 Tap the "Submit Prompt/Question" button to start the analysis. This initiates a chat dialog and
1071
  you can ask follow-up questions. However, the image is not re-analyzed for follow-up dialog.
1072
  Hints:
1073
  1. Better chat and image results are obtained by including detailed descriptions and instructions
1074
  in the prompt.
1075
- 2. Always tap "Restart Conversation" before requesting an image or changing chat topics.
1076
  3. Audio input and output functions depend on the hardware capability of your device.
1077
  4. "Speak Dialog" will voice whatever is currently in the Dialog window. You can repeat it and you
1078
  can edit what's to be spoken. Except: In a chat conversation, spoken dialog will only include
@@ -1130,6 +1134,11 @@ def analyze_image(user, model, prompt):
1130
  # response = completion.choices[0].message.content
1131
  return [completion, status]
1132
 
 
 
 
 
 
1133
 
1134
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
1135
  history = gr.State([])
@@ -1271,7 +1280,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
1271
  with gr.Row():
1272
  prompt_window = gr.Textbox(label = "Prompt or Question", scale=7)
1273
  mode = gr.Dropdown(choices=['Chat', 'News', 'Search'], label='Mode', scale=1, interactive=True)
1274
- news_period = gr.Dropdown(choices=news_interval_choices, interactive=True,label='News Window',scale=1)
 
1275
  gr.Markdown('### **Dialog:**')
1276
  #output_window = gr.Text(container=True, label='Dialog')
1277
  output_window = gr.Markdown(container=True)
@@ -1303,5 +1313,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
1303
  help_button.click(fn=show_help, outputs=output_window)
1304
  button_get_image.click(fn=upload_image,inputs = [prompt_window, user, password], outputs = [image_window2, output_window])
1305
  image_window2.upload(fn=load_image, inputs=[image_window2, user], outputs=[uploaded_image_file, output_window])
 
1306
  # demo.unload(final_clean_up(user))
1307
  demo.launch(share=True, allowed_paths=[dataDir], ssr_mode=False)
 
62
 
63
  special_chat_types = ['math', 'logic']
64
 
65
+ news_interval_choices = [("Day", "pd"), ("Week", "pw"), ("Month", "pm"), ("Year", "py")]
66
 
67
  class Step(BaseModel):
68
  explanation: str
 
664
  os.remove(fpath)
665
  return [None, [], gr.Markdown(value='', label='Dialog', container=True),
666
  gr.Image(visible=False, value=None), gr.Image(visible=False, value=None), '',
667
+ gr.LinePlot(visible=False), gr.Dropdown(value='pd', visible=False), gr.Dropdown(value='Chat')]
668
 
669
  def updatePassword(txt):
670
  password = txt.lower().strip()
 
689
  # return txt
690
 
691
  def chat(prompt, user_window, pwd_window, past, response, gptModel, uploaded_image_file='',
692
+ plot=None, news_interval = 'pd', mode = 'Chat'):
693
  image_gen_model = 'gpt-4o-2024-08-06'
694
  user_window = user_window.lower().strip()
695
  isBoss = False
 
1046
  tapping the audio "Record" button, saying your prompt, then tapping the "Stop" button.
1047
  Your prompt will appear in the Prompt window, and you can edit it there if needed.
1048
  1.3 Text in the "Dialog" window can be spoken by tapping the "Speak Dialog" button.
1049
+ 2. Select Mode:
1050
+ 2.1 Chat mode interacts with the GPT model with info limited to October 2023, when last trained.
1051
+ 2.2 Search mode searches the internet for info using your prompt as search key.
1052
+ 2.3 News mode searches the internet for news posted within the period selected in "News Window"
1053
+ 3. Chat:
1054
+ 3.1 Enter prompt and tap the "Submit Prompt/Question" button. The responses appear in the Dialog window.
1055
+ 3.2 Enter follow-up questions in the Prompt window either by typing or speaking. Tap the voice
1056
  entry "Reset Voice Entry" button to enable additional voice entry. Then tap "Submit Prompt/Question".
1057
+ 3.3 If topic changes or when done chatting, tap the "Restart Conversation" button.
1058
+ 4. Solve math equations or logic problems providing step-by-step analysis:
1059
+ 4.1 Math: Make "solve" the first word in your prompt, followed by the equation, e.g., x^2 - x + 1 = 0
1060
+ 4.2 Logic: Make "puzzle" the first word in your prompt, followed by a detailed description of a logic
1061
  problem with the answer(s) you desire.
1062
+ 5. Make Image:
1063
+ 5.1 Enter description of desired image in prompt window via either typing or voice entry
1064
+ 5.2 Tap the "Make Image" button. This can take a few seconds.
1065
+ 5.3 There is a download button on the image display if your system supports file downloads.
1066
+ 5.4 When done viewing image, tap the "Restart Conversation" button
1067
+ 6. Analyze an Image you provide:
1068
+ 6.1 Enter what you want to know about the image in the prompt window. You can include instructions
1069
+ to write a poem about something in the image, for example. Or just say "what's in this image?"
1070
+ 6.2 Tap the "Upload Image to Analyze" button.
1071
+ 6.3 An empty image box will appear lower left. Drag or upload image into it. It offers web cam or camera
1072
  input also.
1073
+ 6.4 The image should appear. This can take some time with a slow internet connection and large image.
1074
+ 6.5 Tap the "Submit Prompt/Question" button to start the analysis. This initiates a chat dialog and
1075
  you can ask follow-up questions. However, the image is not re-analyzed for follow-up dialog.
1076
  Hints:
1077
  1. Better chat and image results are obtained by including detailed descriptions and instructions
1078
  in the prompt.
1079
+ 2. Always tap "Restart Conversation" before requesting an image or changing topics.
1080
  3. Audio input and output functions depend on the hardware capability of your device.
1081
  4. "Speak Dialog" will voice whatever is currently in the Dialog window. You can repeat it and you
1082
  can edit what's to be spoken. Except: In a chat conversation, spoken dialog will only include
 
1134
  # response = completion.choices[0].message.content
1135
  return [completion, status]
1136
 
1137
+ def mode_change(mode):
1138
+ if mode != "News":
1139
+ return gr.Dropdown(visible=False)
1140
+ else:
1141
+ return gr.Dropdown(visible=True, value='pd')
1142
 
1143
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
1144
  history = gr.State([])
 
1280
  with gr.Row():
1281
  prompt_window = gr.Textbox(label = "Prompt or Question", scale=7)
1282
  mode = gr.Dropdown(choices=['Chat', 'News', 'Search'], label='Mode', scale=1, interactive=True)
1283
+ news_period = gr.Dropdown(choices=news_interval_choices,
1284
+ interactive=True,label='News Window',scale=1, visible=False)
1285
  gr.Markdown('### **Dialog:**')
1286
  #output_window = gr.Text(container=True, label='Dialog')
1287
  output_window = gr.Markdown(container=True)
 
1313
  help_button.click(fn=show_help, outputs=output_window)
1314
  button_get_image.click(fn=upload_image,inputs = [prompt_window, user, password], outputs = [image_window2, output_window])
1315
  image_window2.upload(fn=load_image, inputs=[image_window2, user], outputs=[uploaded_image_file, output_window])
1316
+ mode.change(fn=mode_change, inputs=mode,outputs=news_period)
1317
  # demo.unload(final_clean_up(user))
1318
  demo.launch(share=True, allowed_paths=[dataDir], ssr_mode=False)