ahuang11 commited on
Commit
0b2a850
1 Parent(s): 88bf0ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -56,6 +56,11 @@ fig
56
 
57
 
58
  async def callback(content: str, user: str, instance: pn.chat.ChatInterface):
 
 
 
 
 
59
  # system
60
  messages = [SYSTEM_MESSAGE]
61
 
@@ -87,7 +92,7 @@ def update_plot(event):
87
 
88
 
89
  # instantiate widgets and panes
90
- client = MistralAsyncClient(api_key=os.environ["MISTRAL_API_KEY"])
91
  chat_interface = pn.chat.ChatInterface(
92
  callback=callback,
93
  show_clear=False,
@@ -97,7 +102,7 @@ chat_interface = pn.chat.ChatInterface(
97
  show_reaction_icons=False,
98
  show_copy_icon=False,
99
  ),
100
- height=700,
101
  callback_exception="verbose",
102
  )
103
  matplotlib_pane = pn.pane.Matplotlib(
@@ -120,7 +125,7 @@ tabs = pn.Tabs(
120
  ("Code", code_editor),
121
  )
122
 
123
- sidebar = [chat_interface]
124
  main = [tabs]
125
  template = pn.template.FastListTemplate(
126
  sidebar=sidebar,
 
56
 
57
 
58
  async def callback(content: str, user: str, instance: pn.chat.ChatInterface):
59
+ if not api_key_input.value:
60
+ yield "Please first enter your Mistral API key"
61
+ return
62
+ client = MistralAsyncClient(api_key=api_key_input.value)
63
+
64
  # system
65
  messages = [SYSTEM_MESSAGE]
66
 
 
92
 
93
 
94
  # instantiate widgets and panes
95
+ api_key_input = pn.widgets.PasswordInput(placeholder="Enter your MistralAI API Key")
96
  chat_interface = pn.chat.ChatInterface(
97
  callback=callback,
98
  show_clear=False,
 
102
  show_reaction_icons=False,
103
  show_copy_icon=False,
104
  ),
105
+ height=650,
106
  callback_exception="verbose",
107
  )
108
  matplotlib_pane = pn.pane.Matplotlib(
 
125
  ("Code", code_editor),
126
  )
127
 
128
+ sidebar = [api_key_input, chat_interface]
129
  main = [tabs]
130
  template = pn.template.FastListTemplate(
131
  sidebar=sidebar,