SUPERFIRE777's picture
Update app.py
16573a9
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()