aaron-di commited on
Commit
ae7be4f
·
1 Parent(s): 2b1a645

update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -26
app.py CHANGED
@@ -11,6 +11,9 @@ PLANNER_HISTORY = []
11
  SEARCHER_HISTORY = []
12
 
13
  def rst_mem(history_planner: list, history_searcher: list):
 
 
 
14
  history_planner = []
15
  history_searcher = []
16
  if PLANNER_HISTORY:
@@ -36,6 +39,7 @@ def format_response(gr_history, agent_return):
36
  return
37
 
38
  def predict(history_planner, history_searcher):
 
39
  def streaming(raw_response):
40
  for chunk in raw_response.iter_lines(chunk_size=8192, decode_unicode=False, delimiter=b'\n'):
41
  if chunk:
@@ -79,47 +83,57 @@ def predict(history_planner, history_searcher):
79
  yield history_planner, history_searcher
80
  return history_planner, history_searcher
81
 
82
- with gr.Blocks(css="""
83
- .centered-text {text-align: center; font-family: Arial, sans-serif; color: #333; margin-bottom: 10px;}
84
- .link-container {text-align: center; margin-bottom: 15px;}
85
- .link-container a {text-decoration: none; color: #4A90E2; margin: 0 10px; font-size: 15px;}
86
- .link-container a:hover {color: #357ABD;}
87
- .styled-button {background-color: #357ABD; color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; font-size: 16px; margin: 5px;}
88
- .styled-button:hover {background-color: #285280;}
89
- .input-textbox {border-radius: 5px; border: 1px solid #ccc; padding: 10px; width: 100%;}
90
- """) as demo:
91
- gr.HTML("""<h1 class="centered-text" style="margin-bottom: 5px;">MindSearch Gradio Demo</h1>""")
92
- gr.HTML("""<p class="centered-text" style="margin-top: 0;">MindSearch is an open-source AI Search Engine Framework with Perplexity.ai Pro performance. Deploy your own search engine with either closed-source or open-source LLMs.</p>""")
93
-
94
  gr.HTML("""
95
- <div class="link-container">
96
- <a href="https://github.com/InternLM/MindSearch">🔗 GitHub</a>
97
- <a href="https://arxiv.org/abs/2407.20183">📄 Arxiv</a>
98
- <a href="https://huggingface.co/papers/2407.20183">📚 Hugging Face Papers</a>
99
- <a href="https://huggingface.co/spaces/internlm/MindSearch">🤗 Hugging Face Demo</a>
100
  </div>
101
  """)
102
-
103
  with gr.Row():
104
  with gr.Column(scale=10):
105
  with gr.Row():
106
  with gr.Column():
107
- planner = gr.Chatbot(label='Planner', height=700, show_label=True, show_copy_button=True, bubble_full_width=False, render_markdown=True)
 
 
 
 
 
108
  with gr.Column():
109
- searcher = gr.Chatbot(label='Searcher', height=700, show_label=True, show_copy_button=True, bubble_full_width=False, render_markdown=True)
 
 
 
 
 
110
  with gr.Row():
111
- user_input = gr.Textbox(show_label=False, placeholder='帮我搜索一下 InternLM 开源体系', lines=5, container=False, elem_classes="input-textbox")
 
 
 
 
112
  with gr.Row():
113
  with gr.Column(scale=2):
114
- submitBtn = gr.Button('Submit', elem_classes="styled-button")
115
  with gr.Column(scale=1, min_width=20):
116
- emptyBtn = gr.Button('Clear History', elem_classes="styled-button")
117
 
118
  def user(query, history):
119
  return '', history + [[query, '']]
120
 
121
- submitBtn.click(user, [user_input, planner], [user_input, planner], queue=False).then(predict, [planner, searcher], [planner, searcher])
122
- emptyBtn.click(rst_mem, [planner, searcher], [planner, searcher], queue=False)
 
 
 
123
 
124
  demo.queue()
125
- demo.launch(server_name='0.0.0.0', server_port=7860, inbrowser=True, share=True)
 
 
 
 
11
  SEARCHER_HISTORY = []
12
 
13
  def rst_mem(history_planner: list, history_searcher: list):
14
+ '''
15
+ Reset the chatbot memory.
16
+ '''
17
  history_planner = []
18
  history_searcher = []
19
  if PLANNER_HISTORY:
 
39
  return
40
 
41
  def predict(history_planner, history_searcher):
42
+
43
  def streaming(raw_response):
44
  for chunk in raw_response.iter_lines(chunk_size=8192, decode_unicode=False, delimiter=b'\n'):
45
  if chunk:
 
83
  yield history_planner, history_searcher
84
  return history_planner, history_searcher
85
 
86
+ with gr.Blocks(css=".button-primary { background-color: #4CAF50; color: white; border-radius: 8px; border: none; padding: 10px 20px; font-size: 16px; cursor: pointer; transition: background-color 0.3s ease; } .button-primary:hover { background-color: #45a049; } .button-secondary { background-color: #f44336; color: white; border-radius: 8px; border: none; padding: 10px 20px; font-size: 16px; cursor: pointer; transition: background-color 0.3s ease; } .button-secondary:hover { background-color: #e53935; }") as demo:
87
+ gr.HTML("""<h1 align="center" style="font-family: 'Arial', sans-serif; color: #4A90E2;">MindSearch Gradio Demo</h1>""")
88
+ gr.HTML("""<p style="text-align: center; font-family: Arial, sans-serif; color: #333; max-width: 800px; margin: 0 auto;">MindSearch is an open-source AI Search Engine Framework with Perplexity.ai Pro performance. You can deploy your own Perplexity.ai-style search engine using either closed-source LLMs (GPT, Claude) or open-source LLMs (InternLM2.5-7b-chat).</p>""")
 
 
 
 
 
 
 
 
 
89
  gr.HTML("""
90
+ <div style="text-align: center; font-size: 16px; margin-bottom: 20px;">
91
+ <a href="https://github.com/InternLM/MindSearch" style="margin-right: 15px; text-decoration: none; color: #4A90E2; font-weight: bold;">🔗 GitHub</a>
92
+ <a href="https://arxiv.org/abs/2407.20183" style="margin-right: 15px; text-decoration: none; color: #4A90E2; font-weight: bold;">📄 Arxiv</a>
93
+ <a href="https://huggingface.co/papers/2407.20183" style="margin-right: 15px; text-decoration: none; color: #4A90E2; font-weight: bold;">📚 Hugging Face Papers</a>
94
+ <a href="https://huggingface.co/spaces/internlm/MindSearch" style="text-decoration: none; color: #4A90E2; font-weight: bold;">🤗 Hugging Face Demo</a>
95
  </div>
96
  """)
 
97
  with gr.Row():
98
  with gr.Column(scale=10):
99
  with gr.Row():
100
  with gr.Column():
101
+ planner = gr.Chatbot(label='Planner',
102
+ height=700,
103
+ show_label=True,
104
+ show_copy_button=True,
105
+ bubble_full_width=False,
106
+ render_markdown=True)
107
  with gr.Column():
108
+ searcher = gr.Chatbot(label='Searcher',
109
+ height=700,
110
+ show_label=True,
111
+ show_copy_button=True,
112
+ bubble_full_width=False,
113
+ render_markdown=True)
114
  with gr.Row():
115
+ user_input = gr.Textbox(show_label=False,
116
+ placeholder='帮我搜索一下 InternLM 开源体系',
117
+ lines=5,
118
+ container=False,
119
+ css="border-radius: 8px; border: 1px solid #ddd; padding: 10px;")
120
  with gr.Row():
121
  with gr.Column(scale=2):
122
+ submitBtn = gr.Button('Submit', css="button-primary")
123
  with gr.Column(scale=1, min_width=20):
124
+ emptyBtn = gr.Button('Clear History', css="button-secondary")
125
 
126
  def user(query, history):
127
  return '', history + [[query, '']]
128
 
129
+ submitBtn.click(user, [user_input, planner], [user_input, planner],
130
+ queue=False).then(predict, [planner, searcher],
131
+ [planner, searcher])
132
+ emptyBtn.click(rst_mem, [planner, searcher], [planner, searcher],
133
+ queue=False)
134
 
135
  demo.queue()
136
+ demo.launch(server_name='0.0.0.0',
137
+ server_port=7860,
138
+ inbrowser=True,
139
+ share=True)