Spaces:
Runtime error
Runtime error
Sean-Case
commited on
Commit
•
71c040a
1
Parent(s):
102df35
Changed theme, example set now disappears upon new file load
Browse files- app.py +11 -16
- chatfuncs/chatfuncs.py +6 -0
app.py
CHANGED
@@ -96,9 +96,7 @@ def docs_to_faiss_save(docs_out:PandasDataFrame, embeddings=embeddings):
|
|
96 |
import gradio as gr
|
97 |
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
block = gr.Blocks(css=".gradio-container {background-color: black}")
|
102 |
|
103 |
with block:
|
104 |
ingest_text = gr.State()
|
@@ -131,14 +129,12 @@ with block:
|
|
131 |
|
132 |
submit = gr.Button(value="Send message", variant="secondary", scale = 1)
|
133 |
|
134 |
-
examples_set = gr.
|
135 |
-
|
136 |
-
|
137 |
"What is the vision statement for Lambeth?",
|
138 |
"What are the commitments for Lambeth?",
|
139 |
-
"What are the 2030 outcomes for Lambeth?"]
|
140 |
-
inputs=message,
|
141 |
-
)
|
142 |
|
143 |
with gr.Row():
|
144 |
current_topic = gr.Textbox(label="Keywords related to current conversation topic. If you want to talk about something else, press 'New topic'", placeholder="Keywords related to the conversation topic will appear here")
|
@@ -162,25 +158,24 @@ with block:
|
|
162 |
"<center>Powered by Flan Alpaca and Langchain</a></center>"
|
163 |
)
|
164 |
|
165 |
-
|
166 |
-
# return gr.Examples.update(visible=False)
|
167 |
|
168 |
# Load in a pdf
|
169 |
load_pdf_click = load_pdf.click(ing.parse_file, inputs=[in_pdf], outputs=[ingest_text, current_source]).\
|
170 |
then(ing.text_to_docs, inputs=[ingest_text], outputs=[ingest_docs]).\
|
171 |
-
then(docs_to_faiss_save, inputs=[ingest_docs], outputs=[ingest_embed_out, vectorstore_state])
|
172 |
-
|
173 |
|
174 |
# Load in a webpage
|
175 |
load_web_click = load_web.click(ing.parse_html, inputs=[in_web, in_div], outputs=[ingest_text, ingest_metadata, current_source]).\
|
176 |
then(ing.html_text_to_docs, inputs=[ingest_text, ingest_metadata], outputs=[ingest_docs]).\
|
177 |
-
then(docs_to_faiss_save, inputs=[ingest_docs], outputs=[ingest_embed_out, vectorstore_state])
|
178 |
-
|
179 |
|
180 |
# Load in a webpage
|
181 |
|
182 |
# Click/enter to send message action
|
183 |
-
response_click = submit.click(chatf.get_history_sources_final_input_prompt, inputs=[message, chat_history_state, current_topic, vectorstore_state, embeddings_state], outputs=[chat_history_state, sources, instruction_prompt_out], queue=False).\
|
184 |
then(chatf.turn_off_interactivity, inputs=[message, chatbot], outputs=[message, chatbot], queue=False).\
|
185 |
then(chatf.produce_streaming_answer_chatbot_hf, inputs=[chatbot, instruction_prompt_out], outputs=chatbot)
|
186 |
response_click.then(chatf.highlight_found_text, [chatbot, sources], [sources]).\
|
|
|
96 |
import gradio as gr
|
97 |
|
98 |
|
99 |
+
block = gr.Blocks(theme = gr.themes.Base())#css=".gradio-container {background-color: black}")
|
|
|
|
|
100 |
|
101 |
with block:
|
102 |
ingest_text = gr.State()
|
|
|
129 |
|
130 |
submit = gr.Button(value="Send message", variant="secondary", scale = 1)
|
131 |
|
132 |
+
examples_set = gr.Radio(label="Examples for the Lambeth Borough Plan",
|
133 |
+
#value = "What were the five pillars of the previous borough plan?",
|
134 |
+
choices=["What were the five pillars of the previous borough plan?",
|
135 |
"What is the vision statement for Lambeth?",
|
136 |
"What are the commitments for Lambeth?",
|
137 |
+
"What are the 2030 outcomes for Lambeth?"])
|
|
|
|
|
138 |
|
139 |
with gr.Row():
|
140 |
current_topic = gr.Textbox(label="Keywords related to current conversation topic. If you want to talk about something else, press 'New topic'", placeholder="Keywords related to the conversation topic will appear here")
|
|
|
158 |
"<center>Powered by Flan Alpaca and Langchain</a></center>"
|
159 |
)
|
160 |
|
161 |
+
examples_set.change(fn=chatf.update_message, inputs=[examples_set], outputs=[message])
|
|
|
162 |
|
163 |
# Load in a pdf
|
164 |
load_pdf_click = load_pdf.click(ing.parse_file, inputs=[in_pdf], outputs=[ingest_text, current_source]).\
|
165 |
then(ing.text_to_docs, inputs=[ingest_text], outputs=[ingest_docs]).\
|
166 |
+
then(docs_to_faiss_save, inputs=[ingest_docs], outputs=[ingest_embed_out, vectorstore_state]).\
|
167 |
+
then(chatf.hide_block, outputs = [examples_set])
|
168 |
|
169 |
# Load in a webpage
|
170 |
load_web_click = load_web.click(ing.parse_html, inputs=[in_web, in_div], outputs=[ingest_text, ingest_metadata, current_source]).\
|
171 |
then(ing.html_text_to_docs, inputs=[ingest_text, ingest_metadata], outputs=[ingest_docs]).\
|
172 |
+
then(docs_to_faiss_save, inputs=[ingest_docs], outputs=[ingest_embed_out, vectorstore_state]).\
|
173 |
+
then(chatf.hide_block, outputs = [examples_set])
|
174 |
|
175 |
# Load in a webpage
|
176 |
|
177 |
# Click/enter to send message action
|
178 |
+
response_click = submit.click(chatf.get_history_sources_final_input_prompt, inputs=[message, chat_history_state, current_topic, vectorstore_state, embeddings_state], outputs=[chat_history_state, sources, instruction_prompt_out], queue=False, api_name="retrieval").\
|
179 |
then(chatf.turn_off_interactivity, inputs=[message, chatbot], outputs=[message, chatbot], queue=False).\
|
180 |
then(chatf.produce_streaming_answer_chatbot_hf, inputs=[chatbot, instruction_prompt_out], outputs=chatbot)
|
181 |
response_click.then(chatf.highlight_found_text, [chatbot, sources], [sources]).\
|
chatfuncs/chatfuncs.py
CHANGED
@@ -822,6 +822,12 @@ def ctrans_generate(
|
|
822 |
def turn_off_interactivity(user_message, history):
|
823 |
return gr.update(value="", interactive=False), history + [[user_message, None]]
|
824 |
|
|
|
|
|
|
|
|
|
|
|
|
|
825 |
# # Chat history functions
|
826 |
|
827 |
def clear_chat(chat_history_state, sources, chat_message, current_topic):
|
|
|
822 |
def turn_off_interactivity(user_message, history):
|
823 |
return gr.update(value="", interactive=False), history + [[user_message, None]]
|
824 |
|
825 |
+
def update_message(dropdown_value):
|
826 |
+
return gr.Textbox.update(value=dropdown_value)
|
827 |
+
|
828 |
+
def hide_block():
|
829 |
+
return gr.Radio.update(visible=False)
|
830 |
+
|
831 |
# # Chat history functions
|
832 |
|
833 |
def clear_chat(chat_history_state, sources, chat_message, current_topic):
|