ShawnAI commited on
Commit
1929137
·
1 Parent(s): aa381ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -10
app.py CHANGED
@@ -33,6 +33,8 @@ BUTTON_MIN_WIDTH = 180
33
  STATUS_NOK = "404-MODEL UNREADY-critical"
34
  STATUS_OK = "200-MODEL LOADED-9cf"
35
 
 
 
36
 
37
  def get_logo(inputs, logo) -> str:
38
  return f"""https://img.shields.io/badge/{inputs}?style=flat&logo={logo}&logoColor=white"""
@@ -44,14 +46,20 @@ def get_status(inputs) -> str:
44
  >"""
45
 
46
 
 
 
 
 
47
  MODEL_NULL = get_status(STATUS_NOK)
48
  MODEL_DONE = get_status(STATUS_OK)
49
 
50
- MODEL_WARNING = "Please paste your OpenAI API Key from openai.com and press 'Enter' to initialize this application!"
 
51
 
52
- KEY_INIT = "Initialize Model"
53
- KEY_SUBMIT = "Submit"
54
- KEY_CLEAR = "Clear"
 
55
 
56
  webui_title = """
57
  # OpenAI Chatbot Based on Vector Database
@@ -59,7 +67,7 @@ webui_title = """
59
  """
60
 
61
  dup_link = f'''<a href="https://huggingface.co/spaces/ShawnAI/3GPP-ChatBot?duplicate=true">
62
- <img src="{get_logo("Fork-HuggingFace Space-9cf", "addthis")}"></a> '''
63
 
64
  init_message = f"""Welcome to use 3GPP Chatbot, this demo toolkit is based on OpenAI with LangChain and Pinecone
65
  1. Insert your OpenAI API key and click `{KEY_INIT}`
@@ -147,7 +155,6 @@ def bot(box_message, ref_message, chain, db, top_k):
147
 
148
  if delta_top_k > 0:
149
  docs = doc_similarity(ref_message, db, top_k+delta_top_k)
150
- print(docs)
151
 
152
  all_output = chain({"input_documents": docs,
153
  "question": question,
@@ -170,6 +177,7 @@ def bot(box_message, ref_message, chain, db, top_k):
170
  #----------------------------------------------------------------------------------------------------------
171
 
172
  with gr.Blocks(
 
173
  theme = "Base",
174
  css = """.bigbox {
175
  min-height:200px;
@@ -196,7 +204,7 @@ with gr.Blocks(
196
  init = gr.Button(KEY_INIT) #.style(full_width=False)
197
  model_statusbox = gr.HTML(MODEL_NULL)
198
 
199
- with gr.Tab("3GPP-Chatbot"):
200
  with gr.Row():
201
  with gr.Column(scale=10):
202
  chatbot = gr.Chatbot(elem_classes="bigbox")
@@ -272,13 +280,13 @@ with gr.Blocks(
272
  [chatbot, ref, detail_panel]
273
  )
274
 
275
- print(dup_link)
276
-
277
  clear.click(lambda: (None,None,None), None, [query, ref, chatbot], queue=False)
278
 
279
  #----------------------------------------------------------------------------------------------------------
280
  #----------------------------------------------------------------------------------------------------------
281
 
282
  if __name__ == "__main__":
283
- demo.launch(share=False, inbrowser=True)
 
 
284
 
 
33
  STATUS_NOK = "404-MODEL UNREADY-critical"
34
  STATUS_OK = "200-MODEL LOADED-9cf"
35
 
36
+ FORK_BADGE = "Fork-HuggingFace Space-9cf"
37
+
38
 
39
  def get_logo(inputs, logo) -> str:
40
  return f"""https://img.shields.io/badge/{inputs}?style=flat&logo={logo}&logoColor=white"""
 
46
  >"""
47
 
48
 
49
+ KEY_INIT = "Initialize Model"
50
+ KEY_SUBMIT = "Submit"
51
+ KEY_CLEAR = "Clear"
52
+
53
  MODEL_NULL = get_status(STATUS_NOK)
54
  MODEL_DONE = get_status(STATUS_OK)
55
 
56
+ MODEL_WARNING = f"Please paste your OpenAI API Key from \
57
+ [openai.com](https://platform.openai.com/account/api-keys) and then **{KEY_INIT}**"
58
 
59
+
60
+ TAB_1 = "3GPP Chatbot"
61
+
62
+ FAVICON = './icon.svg'
63
 
64
  webui_title = """
65
  # OpenAI Chatbot Based on Vector Database
 
67
  """
68
 
69
  dup_link = f'''<a href="https://huggingface.co/spaces/ShawnAI/3GPP-ChatBot?duplicate=true">
70
+ <img src="{get_logo(FORK_BADGE, "addthis")}"></a> '''
71
 
72
  init_message = f"""Welcome to use 3GPP Chatbot, this demo toolkit is based on OpenAI with LangChain and Pinecone
73
  1. Insert your OpenAI API key and click `{KEY_INIT}`
 
155
 
156
  if delta_top_k > 0:
157
  docs = doc_similarity(ref_message, db, top_k+delta_top_k)
 
158
 
159
  all_output = chain({"input_documents": docs,
160
  "question": question,
 
177
  #----------------------------------------------------------------------------------------------------------
178
 
179
  with gr.Blocks(
180
+ title = TAB_1,
181
  theme = "Base",
182
  css = """.bigbox {
183
  min-height:200px;
 
204
  init = gr.Button(KEY_INIT) #.style(full_width=False)
205
  model_statusbox = gr.HTML(MODEL_NULL)
206
 
207
+ with gr.Tab(TAB_1):
208
  with gr.Row():
209
  with gr.Column(scale=10):
210
  chatbot = gr.Chatbot(elem_classes="bigbox")
 
280
  [chatbot, ref, detail_panel]
281
  )
282
 
 
 
283
  clear.click(lambda: (None,None,None), None, [query, ref, chatbot], queue=False)
284
 
285
  #----------------------------------------------------------------------------------------------------------
286
  #----------------------------------------------------------------------------------------------------------
287
 
288
  if __name__ == "__main__":
289
+ demo.launch(share = False,
290
+ inbrowser = True,
291
+ favicon_path = FAVICON)
292