Spaces:
Running on Zero
Running on Zero
markrodrigo commited on
Commit ·
09893ec
1
Parent(s): 0965db4
startup
Browse files
app.py
CHANGED
|
@@ -2,6 +2,8 @@ from transformers import pipeline
|
|
| 2 |
import gradio as gr
|
| 3 |
import spaces
|
| 4 |
|
|
|
|
|
|
|
| 5 |
|
| 6 |
pipe = pipeline("text-generation", model="markrodrigo/Llama-3.2-3B-Instruct-Spatial-SQL-1.1", device_map="auto")
|
| 7 |
|
|
@@ -66,7 +68,10 @@ custom_css = """
|
|
| 66 |
|
| 67 |
|
| 68 |
@spaces.GPU
|
| 69 |
-
def respond(user_message, chat_history):
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
chat_history = chat_history or []
|
| 72 |
|
|
@@ -91,7 +96,7 @@ def respond(user_message, chat_history):
|
|
| 91 |
bot_response = sequences[0]["generated_text"].strip()
|
| 92 |
chat_history[-1]["content"] = bot_response
|
| 93 |
|
| 94 |
-
return chat_history, ""
|
| 95 |
|
| 96 |
|
| 97 |
|
|
@@ -120,8 +125,9 @@ with gr.Blocks(title="Text to PostGIS Postgresql via Llama 3.2", css=custom_css)
|
|
| 120 |
inputs=msg,
|
| 121 |
label="Click an example → then click Submit"
|
| 122 |
)
|
| 123 |
-
|
| 124 |
-
|
|
|
|
| 125 |
|
| 126 |
clear_btn = gr.Button("Clear Chat", elem_id="clear-chat-btn")
|
| 127 |
clear_btn.click(lambda: ([], ""), outputs=[chatbot, msg])
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import spaces
|
| 4 |
|
| 5 |
+
# Hidden state for the counter
|
| 6 |
+
counter_state = gr.State(0)
|
| 7 |
|
| 8 |
pipe = pipeline("text-generation", model="markrodrigo/Llama-3.2-3B-Instruct-Spatial-SQL-1.1", device_map="auto")
|
| 9 |
|
|
|
|
| 68 |
|
| 69 |
|
| 70 |
@spaces.GPU
|
| 71 |
+
def respond(user_message, chat_history, counter):
|
| 72 |
+
|
| 73 |
+
# 1. Increment counter
|
| 74 |
+
counter += 1
|
| 75 |
|
| 76 |
chat_history = chat_history or []
|
| 77 |
|
|
|
|
| 96 |
bot_response = sequences[0]["generated_text"].strip()
|
| 97 |
chat_history[-1]["content"] = bot_response
|
| 98 |
|
| 99 |
+
return chat_history, "", counter
|
| 100 |
|
| 101 |
|
| 102 |
|
|
|
|
| 125 |
inputs=msg,
|
| 126 |
label="Click an example → then click Submit"
|
| 127 |
)
|
| 128 |
+
counter_display = gr.Textbox(label="Request Counter", value=0, interactive=False)
|
| 129 |
+
submit_btn.click(fn=respond, inputs=[msg, chatbot, counter_state], outputs=[chatbot, msg, counter_state, counter_display])
|
| 130 |
+
msg.submit(fn=respond, inputs=[msg, chatbot, counter_state], outputs=[chatbot, msg, counter_state, counter_display])
|
| 131 |
|
| 132 |
clear_btn = gr.Button("Clear Chat", elem_id="clear-chat-btn")
|
| 133 |
clear_btn.click(lambda: ([], ""), outputs=[chatbot, msg])
|