Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,14 +16,12 @@ def generate_response(prompt_template, **kwargs):
|
|
| 16 |
top_p=0.8,
|
| 17 |
stream=True
|
| 18 |
)
|
| 19 |
-
response = ""
|
| 20 |
for chunk in stream:
|
| 21 |
-
|
| 22 |
-
yield response # Yield incrementally for streaming
|
| 23 |
|
| 24 |
-
# Wrapper function
|
| 25 |
-
def
|
| 26 |
-
return generate_response(prompt_template, **kwargs)
|
| 27 |
|
| 28 |
# Gradio app interface
|
| 29 |
with gr.Blocks() as app:
|
|
@@ -51,7 +49,7 @@ with gr.Blocks() as app:
|
|
| 51 |
output = gr.Markdown(label="Output", elem_id="latex-output")
|
| 52 |
# Link button to the response wrapper
|
| 53 |
button.click(
|
| 54 |
-
fn=lambda *args:
|
| 55 |
inputs=input_fields,
|
| 56 |
outputs=output,
|
| 57 |
api_name=f"/{tab_name.lower().replace(' ', '_')}_execute"
|
|
|
|
| 16 |
top_p=0.8,
|
| 17 |
stream=True
|
| 18 |
)
|
|
|
|
| 19 |
for chunk in stream:
|
| 20 |
+
yield chunk.choices[0].delta.content # Yield chunks as they are generated
|
|
|
|
| 21 |
|
| 22 |
+
# Wrapper function to combine generator output
|
| 23 |
+
def get_response(prompt_template, **kwargs):
|
| 24 |
+
return "".join(generate_response(prompt_template, **kwargs))
|
| 25 |
|
| 26 |
# Gradio app interface
|
| 27 |
with gr.Blocks() as app:
|
|
|
|
| 49 |
output = gr.Markdown(label="Output", elem_id="latex-output")
|
| 50 |
# Link button to the response wrapper
|
| 51 |
button.click(
|
| 52 |
+
fn=lambda *args: get_response(prompt_template, **dict(zip([inp["key"] for inp in inputs], args))),
|
| 53 |
inputs=input_fields,
|
| 54 |
outputs=output,
|
| 55 |
api_name=f"/{tab_name.lower().replace(' ', '_')}_execute"
|