Spaces:
Runtime error
Runtime error
File size: 1,647 Bytes
b2b08f8 2f32f94 b2b08f8 331a694 b2b08f8 11933be |
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 |
#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,logging
warnings.simplefilter('ignore')
logging.disable(logging.WARNING)
#import pipeline function from transformers.
from transformers import pipeline
#import gradio to begin wrapping ui to the function model.
import gradio as gr
#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() |