Hannah commited on
Commit
3b7d6da
1 Parent(s): cf6cf71
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -4,25 +4,27 @@ 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.Column():
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
- submit_btn = gr.Button("Submit", variant="primary")
23
  response = gr.Textbox(label="Answer")
24
 
25
- submit_btn.click(get_caption, [image, additional_context], outputs=response)
26
-
27
  if __name__ == "__main__":
28
  demo.launch()
 
4
 
5
  client = Client("vikhyatk/moondream1")
6
 
7
+ css = """
8
+ .col {
9
+ width: 300px;
10
+ }
11
+ """
 
12
  def get_caption(image, additional_context):
13
+ question_with_context = "What is this image? Describe this image to someone who is visually impaired."
14
  result = client.predict(image, question_with_context, api_name="/answer_question")
15
+ return result + "\n" + "Additional Context: " + additional_context
16
+
17
+
18
+ with gr.Blocks(css=css) as demo:
19
+ with gr.Group(elem_classes=["col"]):
20
+ with gr.Column():
21
+ image = gr.Image(sources=["upload", "clipboard"], type="filepath", height=330)
22
+ additional_context = gr.Textbox(interactive=True, label="Add additional context here (optional)")
23
+ submit_btn = gr.Button("Submit", variant="primary")
24
 
 
 
 
 
 
25
  response = gr.Textbox(label="Answer")
26
 
27
+ submit_btn.click(get_caption, [image, additional_context], outputs=[response])
28
+
29
  if __name__ == "__main__":
30
  demo.launch()