File size: 1,205 Bytes
917171f
0de0bef
4932931
 
 
 
 
 
 
 
 
 
 
 
 
917171f
4932931
0de0bef
4932931
 
 
 
 
 
 
 
917171f
 
4932931
917171f
4932931
 
0de0bef
4932931
0de0bef
4932931
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
import gradio as gr
import os
from textblob import TextBlob

# Create a simple function for sentiment analysis
def sentiment_analysis(message, history):
    """
    Perform sentiment analysis on the input text and return a formatted result.
    """
    blob = TextBlob(message)
    sentiment = blob.sentiment
    
    assessment = "Positive" if sentiment.polarity > 0 else "Negative" if sentiment.polarity < 0 else "Neutral"
    
    return f"Sentiment Analysis: {assessment}\nPolarity: {sentiment.polarity:.2f}\nSubjectivity: {sentiment.subjectivity:.2f}"

# Create our demo interface
def create_demo():
    # Create a basic ChatInterface with just sentiment analysis
    interface = gr.ChatInterface(
        fn=sentiment_analysis,
        examples=["I love this application, it's amazing!", 
                 "I'm feeling a bit disappointed with the results.",
                 "This is just a neutral statement about facts."],
        title="Sentiment Analysis Chatbot",
        description="Ask me to analyze the sentiment of your text!",
        theme="ocean"
    )
    return interface

# Create the demo
demo = create_demo()

# No cleanup needed for this simplified version
def cleanup():
    pass