Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio_client import Client
|
3 |
+
|
4 |
+
client = Client("vikhyatk/moondream1")
|
5 |
+
|
6 |
+
css = """
|
7 |
+
.col {
|
8 |
+
width: 300px;
|
9 |
+
}
|
10 |
+
"""
|
11 |
+
def get_caption(image, additional_context):
|
12 |
+
question_with_context = "What is this image? Describe this image to someone who is visually impaired."
|
13 |
+
result = client.predict(image, question_with_context, api_name="/answer_question")
|
14 |
+
return result + "\n" + "Additional Context: " + additional_context
|
15 |
+
|
16 |
+
|
17 |
+
with gr.Blocks(css=css) as demo:
|
18 |
+
with gr.Group(elem_classes=["col"]):
|
19 |
+
with gr.Column():
|
20 |
+
image = gr.Image(sources=["upload", "clipboard"], type="filepath", height=330)
|
21 |
+
additional_context = gr.Textbox(interactive=True, label="Add additional context here (optional)")
|
22 |
+
submit_btn = gr.Button("Submit", variant="primary")
|
23 |
+
clear_btn = gr.Button("Clear", variant="secondary")
|
24 |
+
|
25 |
+
response = gr.Textbox(label="Answer")
|
26 |
+
|
27 |
+
submit_btn.click(get_caption, [image, additional_context], outputs=[response])
|
28 |
+
clear_btn.click(lambda x: "", [response], outputs=[response])
|
29 |
+
|
30 |
+
if __name__ == "__main__":
|
31 |
+
demo.launch()
|