Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from gradio_client import Client | |
| client = Client("vikhyatk/moondream1") | |
| css = """ | |
| .col { | |
| width: 300px; | |
| } | |
| """ | |
| def get_caption(image, additional_context): | |
| question_with_context = "What is this image? Describe this image to someone who is visually impaired." | |
| result = client.predict(image, question_with_context, api_name="/answer_question") | |
| return result + "\n" + "Additional Context: " + additional_context | |
| with gr.Blocks(css=css) as demo: | |
| with gr.Group(elem_classes=["col"]): | |
| with gr.Column(): | |
| image = gr.Image(sources=["upload", "clipboard"], type="filepath", height=330) | |
| additional_context = gr.Textbox(interactive=True, label="Add additional context here (optional)") | |
| submit_btn = gr.Button("Submit", variant="primary") | |
| clear_btn = gr.Button("Clear", variant="secondary") | |
| response = gr.Textbox(label="Answer") | |
| submit_btn.click(get_caption, [image, additional_context], outputs=[response]) | |
| clear_btn.click(lambda x: "", [response], outputs=[response]) | |
| if __name__ == "__main__": | |
| demo.launch() | |