Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,46 +37,117 @@ def set_and_generate(url):
|
|
| 37 |
return url, generated_paragraph
|
| 38 |
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
gr.Markdown(title)
|
|
|
|
| 43 |
gr.Markdown(description)
|
| 44 |
|
| 45 |
|
|
|
|
| 46 |
with gr.Row():
|
| 47 |
|
| 48 |
with gr.Column():
|
| 49 |
|
| 50 |
image_url_input = gr.Textbox(label="Image URL")
|
|
|
|
| 51 |
generate_button = gr.Button("Generate Paragraph")
|
| 52 |
|
| 53 |
-
example_1 = gr.Image(value="https://www.animalspot.net/wp-content/uploads/2020/01/Types-of-Falcons.jpg", label="Types of Falcons", interactive=True, shape=(150, 150))
|
| 54 |
-
example_2 = gr.Image(value="https://www.leaders-mena.com/leaders/uploads/2023/01/The-Traditional-Camel-Racing-In-Saudi-Arabia-Unique-Sport-Activity-1024x576.jpg", label="Camel Racing - Saudi Arabia", interactive=True, shape=(150, 150))
|
| 55 |
-
example_3 = gr.Image(value="http://embed.robertharding.com/embed/1161-4342.jpg", label="Urban Street Scene - India", interactive=True, shape=(150, 150))
|
| 56 |
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
with gr.Column():
|
|
|
|
| 59 |
generated_paragraph_output = gr.Textbox(label="Generated Paragraph")
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
generate_button.click(generate_paragraph, inputs=image_url_input, outputs=generated_paragraph_output)
|
| 62 |
|
| 63 |
-
|
| 64 |
|
| 65 |
example_1.click(
|
|
|
|
| 66 |
lambda: set_and_generate("https://www.animalspot.net/wp-content/uploads/2020/01/Types-of-Falcons.jpg"),
|
|
|
|
| 67 |
outputs=[image_url_input, generated_paragraph_output]
|
|
|
|
| 68 |
)
|
| 69 |
|
| 70 |
example_2.click(
|
|
|
|
| 71 |
lambda: set_and_generate("https://www.leaders-mena.com/leaders/uploads/2023/01/The-Traditional-Camel-Racing-In-Saudi-Arabia-Unique-Sport-Activity-1024x576.jpg"),
|
|
|
|
| 72 |
outputs=[image_url_input, generated_paragraph_output]
|
|
|
|
| 73 |
)
|
| 74 |
|
| 75 |
example_3.click(
|
|
|
|
| 76 |
lambda: set_and_generate("http://embed.robertharding.com/embed/1161-4342.jpg"),
|
|
|
|
| 77 |
outputs=[image_url_input, generated_paragraph_output]
|
|
|
|
| 78 |
)
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
# Launch the Gradio interface
|
| 82 |
demo.launch()
|
|
|
|
| 37 |
return url, generated_paragraph
|
| 38 |
|
| 39 |
|
| 40 |
+
# Create the Gradio Blocks interface
|
| 41 |
+
|
| 42 |
+
with gr.Blocks(css=".thumbnail {width: 150px !important; height: 150px !important; object-fit: cover;}") as demo:
|
| 43 |
|
| 44 |
gr.Markdown(title)
|
| 45 |
+
|
| 46 |
gr.Markdown(description)
|
| 47 |
|
| 48 |
|
| 49 |
+
|
| 50 |
with gr.Row():
|
| 51 |
|
| 52 |
with gr.Column():
|
| 53 |
|
| 54 |
image_url_input = gr.Textbox(label="Image URL")
|
| 55 |
+
|
| 56 |
generate_button = gr.Button("Generate Paragraph")
|
| 57 |
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
+
example_1 = gr.Button("Types of Falcons", elem_id="example_1")
|
| 61 |
+
|
| 62 |
+
example_2 = gr.Button("Camel Racing - Saudi Arabia", elem_id="example_2")
|
| 63 |
+
|
| 64 |
+
example_3 = gr.Button("Urban Street Scene - India", elem_id="example_3")
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
# Attach CSS classes for making them look like thumbnails
|
| 69 |
+
|
| 70 |
+
demo.load(lambda: None, every=2, target=example_1, inputs=(), outputs=[], ajax=False)
|
| 71 |
+
|
| 72 |
+
demo.load(lambda: None, every=2, target=example_2, inputs=(), outputs=[], ajax=False)
|
| 73 |
+
|
| 74 |
+
demo.load(lambda: None, every=2, target=example_3, inputs=(), outputs=[], ajax=False)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
|
| 78 |
with gr.Column():
|
| 79 |
+
|
| 80 |
generated_paragraph_output = gr.Textbox(label="Generated Paragraph")
|
| 81 |
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
# Wire click events
|
| 85 |
+
|
| 86 |
generate_button.click(generate_paragraph, inputs=image_url_input, outputs=generated_paragraph_output)
|
| 87 |
|
| 88 |
+
|
| 89 |
|
| 90 |
example_1.click(
|
| 91 |
+
|
| 92 |
lambda: set_and_generate("https://www.animalspot.net/wp-content/uploads/2020/01/Types-of-Falcons.jpg"),
|
| 93 |
+
|
| 94 |
outputs=[image_url_input, generated_paragraph_output]
|
| 95 |
+
|
| 96 |
)
|
| 97 |
|
| 98 |
example_2.click(
|
| 99 |
+
|
| 100 |
lambda: set_and_generate("https://www.leaders-mena.com/leaders/uploads/2023/01/The-Traditional-Camel-Racing-In-Saudi-Arabia-Unique-Sport-Activity-1024x576.jpg"),
|
| 101 |
+
|
| 102 |
outputs=[image_url_input, generated_paragraph_output]
|
| 103 |
+
|
| 104 |
)
|
| 105 |
|
| 106 |
example_3.click(
|
| 107 |
+
|
| 108 |
lambda: set_and_generate("http://embed.robertharding.com/embed/1161-4342.jpg"),
|
| 109 |
+
|
| 110 |
outputs=[image_url_input, generated_paragraph_output]
|
| 111 |
+
|
| 112 |
)
|
| 113 |
|
| 114 |
+
# Configure the CSS for thumbnails
|
| 115 |
+
|
| 116 |
+
demo.css += """
|
| 117 |
+
|
| 118 |
+
#example_1 {
|
| 119 |
+
|
| 120 |
+
background: url("https://www.animalspot.net/wp-content/uploads/2020/01/Types-of-Falcons.jpg");
|
| 121 |
+
|
| 122 |
+
background-size: cover;
|
| 123 |
+
|
| 124 |
+
height: 150px;
|
| 125 |
+
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
#example_2 {
|
| 131 |
+
|
| 132 |
+
background: url("https://www.leaders-mena.com/leaders/uploads/2023/01/The-Traditional-Camel-Racing-In-Saudi-Arabia-Unique-Sport-Activity-1024x576.jpg");
|
| 133 |
+
|
| 134 |
+
background-size: cover;
|
| 135 |
+
|
| 136 |
+
height: 150px;
|
| 137 |
+
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
#example_3 {
|
| 143 |
+
|
| 144 |
+
background: url("http://embed.robertharding.com/embed/1161-4342.jpg");
|
| 145 |
+
|
| 146 |
+
background-size: cover;
|
| 147 |
+
|
| 148 |
+
height: 150px;
|
| 149 |
+
|
| 150 |
+
}
|
| 151 |
|
| 152 |
# Launch the Gradio interface
|
| 153 |
demo.launch()
|