File size: 1,352 Bytes
d35c7cb
 
 
 
 
1c4f0d3
d35c7cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from openai import OpenAI
import os

# AIML API settings
aiml_api_key = os.getenv("AIML_API_KEY")  # Fetch the API key from environment variables
client = OpenAI(api_key=aiml_api_key)

# Function to generate sentiment analysis
def generate_response(feedback, feedback_source):
    prompt = f"Analyze the following {feedback_source} feedback and provide the sentiment (positive, negative, neutral) and key phrases: {feedback}"
    chat_completion = client.chat.completions.create(
        model="o1-mini",
        messages=[
            {"role": "user", "content": prompt},
        ],
        max_tokens=1000,
    )
    return chat_completion.choices[0].message.content

# Streamlit app layout
st.title("Sentiment Analysis Tool")

# Category selection (for feedback context)
category = st.selectbox("Select your feedback source", ("Product Reviews", "Social Media", "Post-purchase Surveys"))

# Input for customer's feedback
query = st.text_area("Enter customer feedback for analysis", placeholder="Paste product review or social media comment here...")

# Button to trigger sentiment analysis
if st.button("Analyze Feedback"):
    if query:
        # Generate sentiment and key phrases
        response = generate_response(query, category)
        st.write(response)
    else:
        st.write("Please enter customer feedback.")