Spaces:
Runtime error
Runtime error
Julian Vanecek
commited on
Commit
·
34916de
1
Parent(s):
ca3f9dd
reverting frontend
Browse files
app.py
CHANGED
|
@@ -164,6 +164,20 @@ with gr.Blocks() as demo:
|
|
| 164 |
# Generate random user ID for this session
|
| 165 |
session_user_id = str(uuid.uuid4())[:8]
|
| 166 |
faq_button = gc.Button("Process")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
faq_output = gc.Markdown(label="Response", value="*Click 'Process' to get a response...*")
|
| 168 |
with gr.Row(): # type: ignore
|
| 169 |
thumbs_down = gc.Button("Report bad response", elem_id="thumbs-down", interactive=True)
|
|
@@ -174,11 +188,22 @@ with gr.Blocks() as demo:
|
|
| 174 |
|
| 175 |
thumbs_down.click(report_bad_response, outputs=[feedback_msg, thumbs_down])
|
| 176 |
|
| 177 |
-
#
|
| 178 |
-
def
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
with gr.Tab(label="Elasticsearch"): # type: ignore
|
| 183 |
gc.Markdown("### Step 1: Natural Language to Query")
|
| 184 |
natural_input = gc.Textbox(label="Describe what you want to search for", lines=3, placeholder="Example: Find all documents containing 'machine learning' in the title")
|
|
|
|
| 164 |
# Generate random user ID for this session
|
| 165 |
session_user_id = str(uuid.uuid4())[:8]
|
| 166 |
faq_button = gc.Button("Process")
|
| 167 |
+
# Loading animation HTML
|
| 168 |
+
loading_html = """
|
| 169 |
+
<div style="display: flex; justify-content: center; align-items: center; min-height: 100px; border: 1px solid #ddd; border-radius: 8px; background-color: #f9f9f9;">
|
| 170 |
+
<div style="display: inline-block; width: 40px; height: 40px; border: 4px solid #f3f3f3; border-top: 4px solid #3498db; border-radius: 50%; animation: spin 1s linear infinite;"></div>
|
| 171 |
+
<style>
|
| 172 |
+
@keyframes spin {
|
| 173 |
+
0% { transform: rotate(0deg); }
|
| 174 |
+
100% { transform: rotate(360deg); }
|
| 175 |
+
}
|
| 176 |
+
</style>
|
| 177 |
+
</div>
|
| 178 |
+
"""
|
| 179 |
+
|
| 180 |
+
faq_loading = gc.HTML(value="", visible=False)
|
| 181 |
faq_output = gc.Markdown(label="Response", value="*Click 'Process' to get a response...*")
|
| 182 |
with gr.Row(): # type: ignore
|
| 183 |
thumbs_down = gc.Button("Report bad response", elem_id="thumbs-down", interactive=True)
|
|
|
|
| 188 |
|
| 189 |
thumbs_down.click(report_bad_response, outputs=[feedback_msg, thumbs_down])
|
| 190 |
|
| 191 |
+
# Combined function to handle loading state and processing
|
| 192 |
+
def process_with_loading(question, model):
|
| 193 |
+
# Show loading, hide response
|
| 194 |
+
yield gr.update(value=loading_html, visible=True), gr.update(value="", visible=False), gr.update(interactive=True), gr.update(value="", visible=False)
|
| 195 |
+
|
| 196 |
+
# Process the question
|
| 197 |
+
result = faq_wrapper(question, session_user_id, model)
|
| 198 |
+
|
| 199 |
+
# Hide loading, show response
|
| 200 |
+
yield gr.update(value="", visible=False), gr.update(value=result, visible=True), gr.update(interactive=True), gr.update(value="", visible=False)
|
| 201 |
+
|
| 202 |
+
faq_button.click(
|
| 203 |
+
process_with_loading,
|
| 204 |
+
inputs=[faq_input, model_selector],
|
| 205 |
+
outputs=[faq_loading, faq_output, thumbs_down, feedback_msg]
|
| 206 |
+
)
|
| 207 |
with gr.Tab(label="Elasticsearch"): # type: ignore
|
| 208 |
gc.Markdown("### Step 1: Natural Language to Query")
|
| 209 |
natural_input = gc.Textbox(label="Describe what you want to search for", lines=3, placeholder="Example: Find all documents containing 'machine learning' in the title")
|