File size: 1,266 Bytes
1ed7018
 
 
 
 
 
 
9d5c1d8
1ed7018
 
 
 
9d5c1d8
 
f0a9d5d
9d5c1d8
f0a9d5d
9d5c1d8
 
 
 
 
 
 
 
 
 
f0a9d5d
1ed7018
 
 
 
 
 
9d5c1d8
1ed7018
 
 
 
9d5c1d8
1ed7018
 
 
 
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 transformers import pipeline
import warnings
import logging
warnings.simplefilter('ignore')
logging.disable(logging.WARNING)




def predict(image):
    cap = pipeline('image-to-text')
    caption = cap(image)


    def sentiment_analysis(shortened):
      pipe = pipeline('text-classification')
      senti = pipe(shortened)
      return senti
    caption_string = str(caption)
    shortened = caption_string.replace("[{'generated_text': '" , "The image is of, ")
    shortened = shortened.replace("'}]" , "")
    sentiment = sentiment_analysis(shortened)
    sentiment_string = ''.join(str(e) for e in sentiment)
    formated_senti = sentiment_string.replace("{'label': ", ", The Tone of the image(sentiment) after analysisng the caption is that is it is ")
    formated_senti = formated_senti.replace("'score': ", "in nature with an average percentage of ")
    output = shortened + formated_senti[0:-2] + '%'
    return output


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-Mod API UI "

interface = gr.Interface(
    fn=predict,
    inputs=input,
    outputs=output,
    title=title,

)
interface.launch()