embed786 commited on
Commit
28ff721
Β·
verified Β·
1 Parent(s): d7ecd59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -10
app.py CHANGED
@@ -1,15 +1,48 @@
1
  import streamlit as st
 
2
 
3
- # Page setup
4
- st.set_page_config(page_title="Hello World App", page_icon="πŸ‘‹", layout="centered")
5
 
6
- # Simple UI
7
- st.title("πŸ‘‹ Hello, Hugging Face + Streamlit!")
8
- st.write("If you see this message, your Space is working correctly πŸš€")
9
 
10
- name = st.text_input("What's your name?")
11
- if st.button("Say Hello"):
12
- if name.strip():
13
- st.success(f"Hello, {name}! πŸŽ‰")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  else:
15
- st.warning("Please enter your name above πŸ‘†")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import requests
3
 
4
+ # βœ… Page setup
5
+ st.set_page_config(page_title="IMDB Sentiment Analyzer 🎬", page_icon="🎬", layout="centered")
6
 
7
+ # Hugging Face model API
8
+ API_URL = "https://api-inference.huggingface.co/models/ibrahim313/my-imdb-sentiment-analyzer"
 
9
 
10
+ # Auth headers if private model
11
+ headers = {}
12
+ if "HF_TOKEN" in st.secrets:
13
+ headers = {"Authorization": f"Bearer {st.secrets['HF_TOKEN']}"}
14
+
15
+ def query(payload):
16
+ response = requests.post(API_URL, headers=headers, json=payload)
17
+ return response.json()
18
+
19
+ # --- UI ---
20
+ st.title("🎬 IMDB Sentiment Analyzer")
21
+ st.markdown("### Predict whether a movie review is **Positive πŸ˜€** or **Negative 😞**")
22
+
23
+ # Pre-filled example
24
+ default_text = "I really loved this movie, the acting was fantastic and the story was emotional."
25
+ user_input = st.text_area("✍️ Enter your review below:", value=default_text, height=150)
26
+
27
+ if st.button("πŸ” Analyze Sentiment"):
28
+ if user_input.strip() == "":
29
+ st.warning("⚠️ Please enter some text")
30
  else:
31
+ result = query({"inputs": user_input})
32
+
33
+ if isinstance(result, list) and len(result) > 0 and isinstance(result[0], list):
34
+ label = result[0][0]["label"]
35
+ score = result[0][0]["score"]
36
+
37
+ # Emoji for label
38
+ emoji = "πŸ˜€" if "pos" in label.lower() else "😞"
39
+
40
+ st.markdown(f"### {emoji} Prediction: **{label}**")
41
+ st.progress(min(max(score, 0.0), 1.0)) # Clamp between 0-1
42
+ st.caption(f"Confidence: {score:.2%}")
43
+ else:
44
+ st.error(f"⚠️ Error from model: {result}")
45
+
46
+ # Footer
47
+ st.markdown("---")
48
+ st.caption("Built with ❀️ using Streamlit + Hugging Face")