-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
45 lines (34 loc) · 1.87 KB
/
app.py
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
import gradio as gr
from PIL import Image
from image_captioning import caption_image_unconditional, caption_image_conditional
import logging
import streamlit as st
# Configure logging
logging.basicConfig(level=logging.DEBUG, filename="app.log")
try:
st.title("Image Captioning Application")
# Gradio interface for unconditional image captioning
def gradio_unconditional_image_caption(image):
return caption_image_unconditional(image)
# Gradio interface for conditional image captioning
def gradio_conditional_image_caption(image, text):
return caption_image_conditional(image, text)
# Define the Gradio interface using the updated syntax
iface_unconditional = gr.Interface(fn=gradio_unconditional_image_caption,
inputs=gr.Image(type="pil"),
outputs="text",
title="Unconditional Image Captioning",
description="Upload an image to get an unconditional caption generated by the BLIP model.")
iface_conditional = gr.Interface(fn=gradio_conditional_image_caption,
inputs=[gr.Image(type="pil"), gr.Textbox(lines=1, placeholder="Enter a prompt")],
outputs="text",
title="Conditional Image Captioning",
description="Upload an image and enter a prompt to get a conditional caption generated by the BLIP model.")
# Combine both interfaces into a single Gradio app
app = gr.TabbedInterface([iface_unconditional, iface_conditional], ["Unconditional", "Conditional"])
# Launch the app
app.launch()
logging.debug("App started successfully.")
except Exception as e:
logging.error(f"Error occurred: {e}")
st.error(f"An error occurred: {e}")