dlflannery commited on
Commit
18fe3a2
·
verified ·
1 Parent(s): f47020d

Update app.py

Browse files

dialog box now plain text, not markdown

Files changed (1) hide show
  1. app.py +12 -30
app.py CHANGED
@@ -26,7 +26,6 @@ import numpy as np
26
  # import matplotlib.pyplot as plt
27
  from pylatexenc.latex2text import LatexNodes2Text
28
 
29
-
30
  load_dotenv(override=True)
31
  key = os.getenv('OPENAI_API_KEY')
32
  users = os.getenv('LOGNAME')
@@ -76,12 +75,13 @@ def test_plot_df():
76
  }
77
  return pd.DataFrame(data)
78
 
 
79
  def md(txt):
80
- if 'DOCTYPE' in txt:
81
- return str(txt.replace('GPT','<br>GPT'))
82
- else:
83
- return str(txt).replace('```', ' ').replace(' ', '&nbsp;&nbsp;').replace(' ', '&nbsp;&nbsp;').replace(' ', '&nbsp;&nbsp;').replace('\n','<br>')
84
- # return txt
85
 
86
  def etz_now():
87
  eastern = pytz.timezone('US/Eastern')
@@ -653,7 +653,7 @@ def chat(prompt, user_window, pwd_window, past, response, gptModel, uploaded_ima
653
  # ymax = float(ymax)
654
  return [past, md(response), None, gptModel, uploaded_image_file, # plot]
655
  gr.LinePlot(plot_df, x="date", y="value", visible=True, x_label_angle=270,
656
- y_lim=[500000, 700000], label="Portfolio Value History")]
657
  elif num >= 3:
658
  if args[1] == 'news':
659
  symbol = ' '.join(args[2:])
@@ -667,25 +667,6 @@ def chat(prompt, user_window, pwd_window, past, response, gptModel, uploaded_ima
667
  gr.LinePlot(plot_df, x="date", y="value", visible=True, x_label_angle=270,
668
  y_lim=[0, ymax],label=f"{symbol.upper()} Recent Prices",
669
  color_map={''})]
670
- # elif arg[1] == 'history':
671
- # symbol = arg[2]
672
- # response = 'ok' # get_
673
-
674
-
675
- # if prompt.startswith('stock values'):
676
- # response = get_stock_report()
677
- # if 'history' in prompt:
678
- # (plot_df, ymax) = stock_history_df(12)
679
- # ymax = float(ymax)
680
- # return [past, response, None, gptModel, uploaded_image_file,
681
- # gr.LinePlot(plot_df, x="date", y="value", visible=True,
682
- # y_lim=[500000, 700000], label="Portfolio Value History")]
683
- # else:
684
- # return [past, response, None, gptModel, uploaded_image_file, plot]
685
- # if prompt.startswith('stock news'):
686
- # symbol = prompt[11:]
687
- # response = get_stock_news(symbol)
688
- # return [past, response, None, gptModel, uploaded_image_file, plot]
689
  if prompt.startswith('stockload'):
690
  create_stock_data_file(prompt[9:].lstrip())
691
  return [past, 'Stock data file created', None, gptModel, uploaded_image_file, plot]
@@ -777,9 +758,9 @@ def chat(prompt, user_window, pwd_window, past, response, gptModel, uploaded_ima
777
  tokens_in = completion.usage.prompt_tokens
778
  tokens_out = completion.usage.completion_tokens
779
  tokens = completion.usage.total_tokens
780
- response += md("\n\n***YOU***: " + prompt + "\n***GPT***: " + reply)
781
  if isBoss:
782
- response += md(f"\n{reporting_model}: tokens in/out = {tokens_in}/{tokens_out}")
783
  if tokens > 40000:
784
  response += "\n\nTHIS DIALOG IS GETTING TOO LONG. PLEASE RESTART CONVERSATION SOON."
785
  past.append({"role":"assistant", "content": final_text})
@@ -1184,8 +1165,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
1184
  speak_output = gr.Button(value="Speak Dialog", visible=True)
1185
  submit_button = gr.Button(value="Submit Prompt/Question")
1186
  prompt_window = gr.Textbox(label = "Prompt or Question")
1187
- gr.Markdown('### **Dialog:**')
1188
- output_window = gr.Markdown(container=True)
 
1189
  with gr.Row():
1190
  with gr.Column():
1191
  image_window2 = gr.Image(visible=False, interactive=True, label='Image to Analyze', type='filepath')
 
26
  # import matplotlib.pyplot as plt
27
  from pylatexenc.latex2text import LatexNodes2Text
28
 
 
29
  load_dotenv(override=True)
30
  key = os.getenv('OPENAI_API_KEY')
31
  users = os.getenv('LOGNAME')
 
75
  }
76
  return pd.DataFrame(data)
77
 
78
+
79
  def md(txt):
80
+ # if 'DOCTYPE' in txt:
81
+ # return str(txt.replace('GPT','<br>GPT'))
82
+ # else:
83
+ # return str(txt).replace('```', ' ').replace(' ', '&nbsp;&nbsp;').replace(' ', '&nbsp;&nbsp;').replace(' ', '&nbsp;&nbsp;').replace('\n','<br>')
84
+ return txt
85
 
86
  def etz_now():
87
  eastern = pytz.timezone('US/Eastern')
 
653
  # ymax = float(ymax)
654
  return [past, md(response), None, gptModel, uploaded_image_file, # plot]
655
  gr.LinePlot(plot_df, x="date", y="value", visible=True, x_label_angle=270,
656
+ y_lim=[400000, 700000], label="Portfolio Value History")]
657
  elif num >= 3:
658
  if args[1] == 'news':
659
  symbol = ' '.join(args[2:])
 
667
  gr.LinePlot(plot_df, x="date", y="value", visible=True, x_label_angle=270,
668
  y_lim=[0, ymax],label=f"{symbol.upper()} Recent Prices",
669
  color_map={''})]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
670
  if prompt.startswith('stockload'):
671
  create_stock_data_file(prompt[9:].lstrip())
672
  return [past, 'Stock data file created', None, gptModel, uploaded_image_file, plot]
 
758
  tokens_in = completion.usage.prompt_tokens
759
  tokens_out = completion.usage.completion_tokens
760
  tokens = completion.usage.total_tokens
761
+ response += md("=================\nYOU:\n" + prompt + "\n=================\nGPT:\n" + reply)
762
  if isBoss:
763
+ response += md(f"\n{reporting_model}: tokens in/out = {tokens_in}/{tokens_out}\n")
764
  if tokens > 40000:
765
  response += "\n\nTHIS DIALOG IS GETTING TOO LONG. PLEASE RESTART CONVERSATION SOON."
766
  past.append({"role":"assistant", "content": final_text})
 
1165
  speak_output = gr.Button(value="Speak Dialog", visible=True)
1166
  submit_button = gr.Button(value="Submit Prompt/Question")
1167
  prompt_window = gr.Textbox(label = "Prompt or Question")
1168
+ #gr.Markdown('### **Dialog:**')
1169
+ output_window = gr.Text(container=True, label='Dialog')
1170
+ # output_window = gr.Markdown(container=True)
1171
  with gr.Row():
1172
  with gr.Column():
1173
  image_window2 = gr.Image(visible=False, interactive=True, label='Image to Analyze', type='filepath')