ShawnAI commited on
Commit
52901ff
·
1 Parent(s): 9da0ae1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -10
app.py CHANGED
@@ -29,6 +29,15 @@ LLM_HISTORY_LEN = 3
29
 
30
  BUTTON_MIN_WIDTH = 150
31
 
 
 
 
 
 
 
 
 
 
32
 
33
  MODEL_WARNING = "Please paste your OpenAI API Key from openai.com and press 'Enter' to initialize this application!"
34
 
@@ -63,12 +72,13 @@ def init_model(api_key):
63
  db = Pinecone.from_existing_index(index_name = PINECONE_INDEX,
64
  embedding = embeddings)
65
 
66
- return api_key, chain, db, None
67
  else:
68
- return None,None,None,None
69
  except Exception as e:
70
  print(e)
71
- return None,None,None,None
 
72
 
73
  def get_chat_history(inputs) -> str:
74
  res = []
@@ -127,11 +137,18 @@ with gr.Blocks(css=""".bigbox {
127
  gr.Markdown(init_message)
128
 
129
  with gr.Row():
130
- api_textbox = gr.Textbox(
131
- value = OPENAI_API_KEY,
132
- placeholder = "Paste Your OpenAI API Key (sk-...) and Hit ENTER",
133
- show_label=False, lines=1, type='password')
134
- init = gr.Button("Initialize Model").style(full_width=False)
 
 
 
 
 
 
 
135
 
136
  with gr.Tab("3GPP-Chatbot"):
137
  with gr.Row():
@@ -169,10 +186,10 @@ with gr.Blocks(css=""".bigbox {
169
 
170
  api_textbox.submit(init_model,
171
  api_textbox,
172
- [api_textbox, llm_chain, vector_db, chatbot])
173
  init.click(init_model,
174
  api_textbox,
175
- [api_textbox, llm_chain, vector_db, chatbot])
176
 
177
  submit.click(user,
178
  [query, chatbot],
 
29
 
30
  BUTTON_MIN_WIDTH = 150
31
 
32
+ STATUS_NOK = "404-MODEL UNREADY-red"
33
+ STATUS_OK = "200-MODEL LOADED-brightgreen"
34
+
35
+ def get_status(inputs) -> str:
36
+ return f"""<img src="https://img.shields.io/badge/{inputs}?style=flat"></a>"""
37
+
38
+
39
+ MODEL_NULL = get_status(STATUS_NOK)
40
+ MODEL_DONE = get_status(STATUS_OK)
41
 
42
  MODEL_WARNING = "Please paste your OpenAI API Key from openai.com and press 'Enter' to initialize this application!"
43
 
 
72
  db = Pinecone.from_existing_index(index_name = PINECONE_INDEX,
73
  embedding = embeddings)
74
 
75
+ return api_key, MODEL_DONE, chain, db, None
76
  else:
77
+ return None,MODEL_NULL,None,None,None
78
  except Exception as e:
79
  print(e)
80
+ return None,MODEL_NULL,None,None,None
81
+
82
 
83
  def get_chat_history(inputs) -> str:
84
  res = []
 
137
  gr.Markdown(init_message)
138
 
139
  with gr.Row():
140
+ with gr.Column(scale=9):
141
+ api_textbox = gr.Textbox(
142
+ label = "OpenAI API Key",
143
+ value = OPENAI_API_KEY,
144
+ placeholder = "Paste Your OpenAI API Key (sk-...) and Hit ENTER",
145
+ lines=1,
146
+ type='password')
147
+
148
+ with gr.Column(scale=1, min_width=BUTTON_MIN_WIDTH):
149
+
150
+ init = gr.Button("Initialize Model").style(full_width=False)
151
+ model_statusbox = gr.HTML(MODEL_NULL)
152
 
153
  with gr.Tab("3GPP-Chatbot"):
154
  with gr.Row():
 
186
 
187
  api_textbox.submit(init_model,
188
  api_textbox,
189
+ [api_textbox, model_statusbox, llm_chain, vector_db, chatbot])
190
  init.click(init_model,
191
  api_textbox,
192
+ [api_textbox, model_statusbox, llm_chain, vector_db, chatbot])
193
 
194
  submit.click(user,
195
  [query, chatbot],