Spaces:
Runtime error
Runtime error
Hannah
commited on
Commit
·
992501a
1
Parent(s):
6603c80
add demo
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from gradio_client import Client
|
| 4 |
+
|
| 5 |
+
client = Client("vikhyatk/moondream1")
|
| 6 |
+
|
| 7 |
+
result = client.predict(
|
| 8 |
+
"https://hips.hearstapps.com/hmg-prod/images/dog-puppy-on-garden-royalty-free-image-1586966191.jpg",
|
| 9 |
+
"What is this image? Describe this image to someone who is visually impaired.",
|
| 10 |
+
api_name="/answer_question",
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
def get_caption(image, additional_context):
|
| 14 |
+
question_with_context = "What is this image? Describe this image to someone who is visually impaired. " + additional_context
|
| 15 |
+
result = client.predict(image, question_with_context, api_name="/answer_question")
|
| 16 |
+
return result
|
| 17 |
+
|
| 18 |
+
with gr.Blocks() as demo:
|
| 19 |
+
with gr.Row():
|
| 20 |
+
image = gr.Image(sources=["upload", "clipboard"], type="filepath", height=300)
|
| 21 |
+
additional_context = gr.Textbox(interactive=True, label="Add additional context here (optional)")
|
| 22 |
+
with gr.Row():
|
| 23 |
+
response = gr.Textbox(label="Answer")
|
| 24 |
+
submit_btn = gr.Button("Submit", variant="primary")
|
| 25 |
+
|
| 26 |
+
submit_btn.click(get_caption, [image, additional_context], outputs=response)
|
| 27 |
+
|
| 28 |
+
if __name__ == "__main__":
|
| 29 |
+
demo.launch()
|