File size: 1,022 Bytes
cae88e7
3419893
04f4d48
9d859d6
cae88e7
 
3419893
cae88e7
34de3ec
 
cae88e7
b9ae502
cae88e7
 
 
 
c073165
cae88e7
9c1a0aa
cae88e7
9c1a0aa
cae88e7
9c1a0aa
cae88e7
34de3ec
ce57911
16573a9
9c1a0aa
 
34de3ec
 
bf43737
3180ee0
9c1a0aa
ce57911
3419893
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
import gradio as gr
from mtranslate import translate
from textblob import TextBlob

def analyze(sentence):
    # Translate the sentence from Japanese to English
    en_sentence = translate(sentence, "en")

    jp_sentence = translate(en_sentence, "ja")

    # Create a TextBlob object for the sentence
    blob = TextBlob(en_sentence)
    
    # Get the polarity score for the sentence
    polarity_score = blob.sentiment.polarity
    
    # Return a result
    if polarity_score > 0:
        sentiment = "ポジティブ"
    elif polarity_score == 0:
        sentiment = "ニュートラル"
    else:
        sentiment = "ネガティブ"

    return (en_sentence, jp_sentence, sentiment)

input_format = gr.Textbox(label="文章")

output_format = [gr.Textbox(label="翻訳後の文章"),
                 gr.Textbox(label="和訳"),
                 gr.Textbox(label="感情")]
    
iface = gr.Interface(fn=analyze,
                     inputs=input_format,
                     outputs=output_format)
iface.launch()