feat: Fix Gradio warnings and implement ZeroGPU startup hook for vision pipeline
Browse files- app.py +23 -10
- tools/vision.py +15 -0
- ui/layout.py +2 -1
app.py
CHANGED
|
@@ -8,19 +8,32 @@ try:
|
|
| 8 |
except FileNotFoundError:
|
| 9 |
custom_css = ""
|
| 10 |
|
| 11 |
-
# Build the Gradio App
|
| 12 |
-
demo = gr.Blocks(
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
neutral_hue="slate",
|
| 17 |
-
font=[gr.themes.GoogleFont("Inter"), "sans-serif"]
|
| 18 |
-
)
|
| 19 |
)
|
| 20 |
|
| 21 |
with demo:
|
| 22 |
# Initialize the UI layout from the ui folder
|
| 23 |
-
create_ui()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
if __name__ == "__main__":
|
| 26 |
-
demo.launch()
|
|
|
|
| 8 |
except FileNotFoundError:
|
| 9 |
custom_css = ""
|
| 10 |
|
| 11 |
+
# Build the Gradio App
|
| 12 |
+
demo = gr.Blocks()
|
| 13 |
+
my_theme = gr.themes.Default(
|
| 14 |
+
primary_hue="blue",
|
| 15 |
+
neutral_hue="slate"
|
|
|
|
|
|
|
|
|
|
| 16 |
)
|
| 17 |
|
| 18 |
with demo:
|
| 19 |
# Initialize the UI layout from the ui folder
|
| 20 |
+
image_input, audio_input, submit_btn, chatbot, msg_input = create_ui()
|
| 21 |
+
|
| 22 |
+
# Bind the submit button to the vision function
|
| 23 |
+
def handle_analyze(image):
|
| 24 |
+
from tools.vision import process_receipt_image
|
| 25 |
+
if not image:
|
| 26 |
+
return [("System", "Please upload an image first!")]
|
| 27 |
+
|
| 28 |
+
# Trigger the ZeroGPU
|
| 29 |
+
result = process_receipt_image(image)
|
| 30 |
+
return [("User", "Uploaded a bill..."), ("Agent", result)]
|
| 31 |
+
|
| 32 |
+
submit_btn.click(
|
| 33 |
+
fn=handle_analyze,
|
| 34 |
+
inputs=[image_input],
|
| 35 |
+
outputs=[chatbot]
|
| 36 |
+
)
|
| 37 |
|
| 38 |
if __name__ == "__main__":
|
| 39 |
+
demo.launch(theme=my_theme, css=custom_css)
|
tools/vision.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
@spaces.GPU
|
| 5 |
+
def process_receipt_image(image_path):
|
| 6 |
+
"""
|
| 7 |
+
Milestone 2: Vision Pipeline.
|
| 8 |
+
For now, this just verifies the ZeroGPU is working.
|
| 9 |
+
We will load the massive MiniCPM-V-2_6 model here next.
|
| 10 |
+
"""
|
| 11 |
+
if torch.cuda.is_available():
|
| 12 |
+
gpu_name = torch.cuda.get_device_name(0)
|
| 13 |
+
return f"Success! ZeroGPU is awake. Allocated: {gpu_name}. Ready to load MiniCPM-V!"
|
| 14 |
+
else:
|
| 15 |
+
return "Warning: Running on CPU. ZeroGPU did not wake up."
|
ui/layout.py
CHANGED
|
@@ -24,4 +24,5 @@ def create_ui():
|
|
| 24 |
chatbot = gr.Chatbot(label="Agent", elem_classes=["chat-window"], height=500)
|
| 25 |
msg_input = gr.Textbox(label="Ask a question", placeholder="e.g. How much did I spend on junk food?", elem_classes=["chat-input"])
|
| 26 |
|
| 27 |
-
#
|
|
|
|
|
|
| 24 |
chatbot = gr.Chatbot(label="Agent", elem_classes=["chat-window"], height=500)
|
| 25 |
msg_input = gr.Textbox(label="Ask a question", placeholder="e.g. How much did I spend on junk food?", elem_classes=["chat-input"])
|
| 26 |
|
| 27 |
+
# Return the components so app.py can bind events to them
|
| 28 |
+
return image_input, audio_input, submit_btn, chatbot, msg_input
|