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") # 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 = "Positive" elif polarity_score == 0: sentiment = "Neutral" else: sentiment = "Negative" return (en_sentence, sentiment) output_format = [ {"type": "text", "label": "Translated Sentence"}, {"type": "text", "label": "Sentiment Analysis Result"}] iface = gr.Interface(fn=analyze, inputs="text", outputs=output_format) iface.launch()