Spaces:
Sleeping
Sleeping
File size: 1,794 Bytes
e82b768 a4690cb e82b768 a4690cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
import gradio as gr
from agents import build_graph
# Initialize the graph
graph = build_graph()
def process_and_display(image, voice):
# Initialize state
state = {"image": image, "voice": voice, "caption": "", "description": ""}
# Run the graph
result = graph.invoke(state)
# Return the caption and description
return result["caption"], result["description"]
def create_interface():
with gr.Blocks() as demo:
gr.Markdown("# Image Description with Voice Personas")
gr.Markdown("""
This app takes an image and generates a description using a selected voice persona.
1. Upload an image
2. Select a voice persona from the dropdown
3. Click "Generate Description" to see the results
""")
with gr.Row():
with gr.Column():
image_input = gr.Image(type="pil", label="Upload an Image")
voice_dropdown = gr.Dropdown(
choices=[
"scurvy-ridden pirate",
"forgetful wizard",
"sarcastic teenager",
],
label="Select a Voice",
value="scurvy-ridden pirate",
)
submit_button = gr.Button("Generate Description")
with gr.Column():
caption_output = gr.Textbox(label="Image Caption")
description_output = gr.Textbox(label="Voice Description")
submit_button.click(
fn=process_and_display,
inputs=[image_input, voice_dropdown],
outputs=[caption_output, description_output],
)
return demo
# Launch the app
demo = create_interface()
if __name__ == "__main__":
demo.launch()
|