File size: 1,150 Bytes
1ed7018
 
 
 
 
 
 
9d5c1d8
1ed7018
 
9d5c1d8
 
f0a9d5d
9d5c1d8
1af89f9
9d5c1d8
 
6e993f7
9d5c1d8
6e993f7
 
 
 
 
9d5c1d8
6e993f7
56ce111
6e993f7
56ce111
6e993f7
56ce111
6e993f7
56ce111
f0a9d5d
1ed7018
 
 
 
 
 
6226cd0
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
46
47
48
49
50
51
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('sentiment-analysis')
      senti = pipe(shortened)
      return senti

    caption_string = str(caption)

    sentiment = sentiment_analysis(caption_string[21:-1])



    sentiment_string = ''.join(str(e) for e in sentiment)

    image_caption = caption_string[21:-3]

    percentage =sentiment_string[34: -14]

    tone =  sentiment_string[11:-31]

    output = 'the image is of, ' + image_caption + ", the overall tone of the image's content is - "+ tone + " with a approx "+ percentage + "% score"
    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 with Sentiment-Analysis UI "

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

)
interface.launch()