Spaces:
Sleeping
Sleeping
| 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") | |