suryabbrj's picture
Duplicate from suryabbrj/CollegeProjectV2
3200d15
raw
history blame contribute delete
No virus
1.6 kB
import gradio as gr
from transformers import pipeline
# install gradio library for the ui
#!pip install -q gradio
# install transformers to include pipeline to import and run pretrained image-to-text model.
#!pip install transformers
# ignore model warnings from logging to the console.
import warnings
import logging
warnings.simplefilter('ignore')
logging.disable(logging.WARNING)
# import pipeline function from transformers.
# import gradio to begin wrapping ui to the function model.
# import pretrained model and its weights to the predict funtion [this is an optional step that may help speed up prediction by caching the weights to the ml platform. this only logs the prediction to the console, and thus the prediction is not entirely useful in application.]
cap = pipeline('image-to-text')
# uncomment and pass any url/path to the var img and invoke function to predict the caption.
# url = 'https://cdn.pixabay.com/photo/2023/02/25/12/30/man-7813108_960_720.jpg'
# cap(url)
# add sentiment analysis to the caption to identify possible suicidal and depression symptoms!!
def predict(image):
cap = pipeline('image-to-text')
caption = cap(image)
output = str(caption)
return output[21:-4]
input = gr.inputs.Image(
label="Upload your Image and wait for 8-12 seconds!", type='pil', optional=False)
output = gr.outputs.Textbox(label="Captions")
title = "Content ModX UI "
interface = gr.Interface(
fn=predict,
inputs=input,
theme="grass",
outputs=output,
title=title,
flagging_options=["correct", "just okay", "wrong"],
)
interface.launch()