Spaces:
Sleeping
Sleeping
Aditya DN commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,9 +13,8 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
| 13 |
model.to(device)
|
| 14 |
|
| 15 |
# Captioning function
|
| 16 |
-
def generate_caption(
|
| 17 |
# Choose image from upload or webcam
|
| 18 |
-
image = webcam_img if webcam_img is not None else upload_img
|
| 19 |
if image is None:
|
| 20 |
return "No image provided."
|
| 21 |
# Preprocess
|
|
@@ -29,13 +28,12 @@ def generate_caption(upload_img, webcam_img):
|
|
| 29 |
with gr.Blocks() as demo:
|
| 30 |
gr.Markdown("# Image Captioning with Gradio")
|
| 31 |
with gr.Row():
|
| 32 |
-
upload_input = gr.Image(
|
| 33 |
-
webcam_input = gr.Image(source="webcam", type="pil", label="Use Camera")
|
| 34 |
output_text = gr.Textbox(label="Caption", interactive=False)
|
| 35 |
generate_btn = gr.Button("Generate Caption")
|
| 36 |
generate_btn.click(
|
| 37 |
fn=generate_caption,
|
| 38 |
-
inputs=
|
| 39 |
outputs=output_text
|
| 40 |
)
|
| 41 |
|
|
|
|
| 13 |
model.to(device)
|
| 14 |
|
| 15 |
# Captioning function
|
| 16 |
+
def generate_caption(image):
|
| 17 |
# Choose image from upload or webcam
|
|
|
|
| 18 |
if image is None:
|
| 19 |
return "No image provided."
|
| 20 |
# Preprocess
|
|
|
|
| 28 |
with gr.Blocks() as demo:
|
| 29 |
gr.Markdown("# Image Captioning with Gradio")
|
| 30 |
with gr.Row():
|
| 31 |
+
upload_input = gr.Image(sources=["upload", "webcam", "clipboard"], type="pil", label="Upload Image")
|
|
|
|
| 32 |
output_text = gr.Textbox(label="Caption", interactive=False)
|
| 33 |
generate_btn = gr.Button("Generate Caption")
|
| 34 |
generate_btn.click(
|
| 35 |
fn=generate_caption,
|
| 36 |
+
inputs=upload_input,
|
| 37 |
outputs=output_text
|
| 38 |
)
|
| 39 |
|