Spaces:
Build error
Build error
Julian Vanecek commited on
Commit ·
1b05784
1
Parent(s): 34916de
reverting frontend
Browse files
app.py
CHANGED
|
@@ -143,6 +143,8 @@ def faq_wrapper(question, user_id, model):
|
|
| 143 |
result = chunk
|
| 144 |
# Convert literal \n characters to actual newlines
|
| 145 |
result = result.replace('\\n', '\n')
|
|
|
|
|
|
|
| 146 |
return result
|
| 147 |
|
| 148 |
def elasticsearch_generate(natural_input):
|
|
@@ -177,8 +179,14 @@ with gr.Blocks() as demo:
|
|
| 177 |
</div>
|
| 178 |
"""
|
| 179 |
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
with gr.Row(): # type: ignore
|
| 183 |
thumbs_down = gc.Button("Report bad response", elem_id="thumbs-down", interactive=True)
|
| 184 |
feedback_msg = gc.Markdown(visible=False)
|
|
@@ -190,19 +198,25 @@ with gr.Blocks() as demo:
|
|
| 190 |
|
| 191 |
# Combined function to handle loading state and processing
|
| 192 |
def process_with_loading(question, model):
|
| 193 |
-
# Show loading
|
| 194 |
-
yield gr.update(value=loading_html
|
| 195 |
|
| 196 |
# Process the question
|
| 197 |
result = faq_wrapper(question, session_user_id, model)
|
| 198 |
|
| 199 |
-
#
|
| 200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
faq_button.click(
|
| 203 |
process_with_loading,
|
| 204 |
inputs=[faq_input, model_selector],
|
| 205 |
-
outputs=[
|
|
|
|
| 206 |
)
|
| 207 |
with gr.Tab(label="Elasticsearch"): # type: ignore
|
| 208 |
gc.Markdown("### Step 1: Natural Language to Query")
|
|
|
|
| 143 |
result = chunk
|
| 144 |
# Convert literal \n characters to actual newlines
|
| 145 |
result = result.replace('\\n', '\n')
|
| 146 |
+
# Remove leading/trailing quotes if present
|
| 147 |
+
result = result.strip('"\'')
|
| 148 |
return result
|
| 149 |
|
| 150 |
def elasticsearch_generate(natural_input):
|
|
|
|
| 179 |
</div>
|
| 180 |
"""
|
| 181 |
|
| 182 |
+
# Empty bounding box HTML
|
| 183 |
+
empty_box_html = """
|
| 184 |
+
<div style="min-height: 100px; border: 1px solid #ddd; border-radius: 8px; background-color: #f9f9f9; padding: 20px; display: flex; align-items: center; justify-content: center; color: #666;">
|
| 185 |
+
<em>Click 'Process' to get a response...</em>
|
| 186 |
+
</div>
|
| 187 |
+
"""
|
| 188 |
+
|
| 189 |
+
faq_output = gc.HTML(label="Response", value=empty_box_html)
|
| 190 |
with gr.Row(): # type: ignore
|
| 191 |
thumbs_down = gc.Button("Report bad response", elem_id="thumbs-down", interactive=True)
|
| 192 |
feedback_msg = gc.Markdown(visible=False)
|
|
|
|
| 198 |
|
| 199 |
# Combined function to handle loading state and processing
|
| 200 |
def process_with_loading(question, model):
|
| 201 |
+
# Show loading spinner
|
| 202 |
+
yield gr.update(value=loading_html)
|
| 203 |
|
| 204 |
# Process the question
|
| 205 |
result = faq_wrapper(question, session_user_id, model)
|
| 206 |
|
| 207 |
+
# Format response in bounding box and show result
|
| 208 |
+
response_html = f"""
|
| 209 |
+
<div style="min-height: 100px; border: 1px solid #ddd; border-radius: 8px; background-color: #ffffff; padding: 20px;">
|
| 210 |
+
<div style="white-space: pre-wrap; line-height: 1.5;">{result}</div>
|
| 211 |
+
</div>
|
| 212 |
+
"""
|
| 213 |
+
yield gr.update(value=response_html)
|
| 214 |
|
| 215 |
faq_button.click(
|
| 216 |
process_with_loading,
|
| 217 |
inputs=[faq_input, model_selector],
|
| 218 |
+
outputs=[faq_output],
|
| 219 |
+
show_progress=False
|
| 220 |
)
|
| 221 |
with gr.Tab(label="Elasticsearch"): # type: ignore
|
| 222 |
gc.Markdown("### Step 1: Natural Language to Query")
|