Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -71,24 +71,103 @@ def process_answer(img, answer):
|
|
71 |
|
72 |
return gr.update(visible=False, value=None)
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
demo.queue().launch()
|
|
|
71 |
|
72 |
return gr.update(visible=False, value=None)
|
73 |
|
74 |
+
custom_css = """
|
75 |
+
.container {
|
76 |
+
max-width: 900px;
|
77 |
+
margin: auto;
|
78 |
+
padding: 20px;
|
79 |
+
}
|
80 |
+
|
81 |
+
.header {
|
82 |
+
text-align: center;
|
83 |
+
margin-bottom: 2rem;
|
84 |
+
}
|
85 |
+
|
86 |
+
.github-link {
|
87 |
+
display: inline-block;
|
88 |
+
padding: 8px 16px;
|
89 |
+
background-color: #24292e;
|
90 |
+
color: white;
|
91 |
+
text-decoration: none;
|
92 |
+
border-radius: 6px;
|
93 |
+
margin-top: 10px;
|
94 |
+
}
|
95 |
+
|
96 |
+
.github-link:hover {
|
97 |
+
background-color: #2f363d;
|
98 |
+
}
|
99 |
+
|
100 |
+
.input-section {
|
101 |
+
margin: 20px 0;
|
102 |
+
}
|
103 |
+
|
104 |
+
.response-section {
|
105 |
+
margin-top: 20px;
|
106 |
+
padding: 20px;
|
107 |
+
border-radius: 8px;
|
108 |
+
background-color: #f8f9fa;
|
109 |
+
}
|
110 |
+
"""
|
111 |
+
|
112 |
+
with gr.Blocks(css=custom_css) as demo:
|
113 |
+
with gr.Column(elem_classes="container"):
|
114 |
+
gr.Markdown(
|
115 |
+
"""
|
116 |
+
<div class="header">
|
117 |
+
# 🌔 Moondream VL
|
118 |
+
### A Tiny Vision Language Model
|
119 |
+
<a href="https://github.com/vikhyat/moondream" class="github-link" target="_blank">
|
120 |
+
📦 GitHub Repository
|
121 |
+
</a>
|
122 |
+
</div>
|
123 |
+
""",
|
124 |
+
elem_classes="header"
|
125 |
+
)
|
126 |
+
|
127 |
+
with gr.Column(elem_classes="input-section"):
|
128 |
+
img = gr.Image(
|
129 |
+
type="pil",
|
130 |
+
label="Upload an Image",
|
131 |
+
elem_id="image-upload",
|
132 |
+
height=400
|
133 |
+
)
|
134 |
+
|
135 |
+
with gr.Row():
|
136 |
+
prompt = gr.Textbox(
|
137 |
+
label="Your Question",
|
138 |
+
placeholder="Ask something about the image...",
|
139 |
+
value="Describe this image.",
|
140 |
+
scale=4
|
141 |
+
)
|
142 |
+
submit = gr.Button(
|
143 |
+
"✨ Analyze",
|
144 |
+
variant="primary",
|
145 |
+
scale=1
|
146 |
+
)
|
147 |
+
|
148 |
+
with gr.Column(elem_classes="response-section"):
|
149 |
+
output = gr.Markdown(label="AI Response")
|
150 |
+
ann = gr.Image(
|
151 |
+
visible=False,
|
152 |
+
label="Annotated Image"
|
153 |
+
)
|
154 |
+
|
155 |
+
# Event handlers
|
156 |
+
submit.click(
|
157 |
+
answer_question,
|
158 |
+
inputs=[img, prompt],
|
159 |
+
outputs=output
|
160 |
+
)
|
161 |
+
prompt.submit(
|
162 |
+
answer_question,
|
163 |
+
inputs=[img, prompt],
|
164 |
+
outputs=output
|
165 |
+
)
|
166 |
+
output.change(
|
167 |
+
process_answer,
|
168 |
+
inputs=[img, output],
|
169 |
+
outputs=ann,
|
170 |
+
show_progress=False
|
171 |
+
)
|
172 |
|
173 |
demo.queue().launch()
|