File size: 1,748 Bytes
c43c95a
28ff721
c43c95a
28ff721
 
c43c95a
28ff721
 
c43c95a
249d93a
28ff721
45558ba
 
 
 
28ff721
 
249d93a
28ff721
 
 
 
 
 
 
 
 
 
 
 
 
c43c95a
28ff721
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
import streamlit as st
import requests

# βœ… Page setup
st.set_page_config(page_title="IMDB Sentiment Analyzer 🎬", page_icon="🎬", layout="centered")

# Hugging Face model API
API_URL = "https://api-inference.huggingface.co/models/ibrahim313/my-imdb-sentiment-analyzer"

#HF_TOKEN
# Auth headers if private model
#headers = {}
#if "hfsecret" in st.secrets:
print(f"token : {st.secrets['hfsecret']}")
headers = {"Authorization": f"Bearer {st.secrets['hfsecret']}"}

def query(payload):
    response = requests.post(API_URL, headers="", json=payload)
    return response.json()

# --- UI ---
st.title("🎬 IMDB Sentiment Analyzer")
st.markdown("### Predict whether a movie review is **Positive πŸ˜€** or **Negative 😞**")

# Pre-filled example
default_text = "I really loved this movie, the acting was fantastic and the story was emotional."
user_input = st.text_area("✍️ Enter your review below:", value=default_text, height=150)

if st.button("πŸ” Analyze Sentiment"):
    if user_input.strip() == "":
        st.warning("⚠️ Please enter some text")
    else:
        result = query({"inputs": user_input})

        if isinstance(result, list) and len(result) > 0 and isinstance(result[0], list):
            label = result[0][0]["label"]
            score = result[0][0]["score"]

            # Emoji for label
            emoji = "πŸ˜€" if "pos" in label.lower() else "😞"

            st.markdown(f"### {emoji} Prediction: **{label}**")
            st.progress(min(max(score, 0.0), 1.0))  # Clamp between 0-1
            st.caption(f"Confidence: {score:.2%}")
        else:
            st.error(f"⚠️ Error from model: {result}")

# Footer
st.markdown("---")
st.caption("Built with ❀️ using Streamlit + Hugging Face")