Game_Built / app.py
AqsaAbbasi26's picture
Create app.py
97f5be6 verified
raw
history blame contribute delete
980 Bytes
import streamlit as st
import requests
API_URL = "https://api-inference.huggingface.co/models/bhadresh-savani/distilbert-base-uncased-emotion"
API_TOKEN = "your_token_here" # Replace with your Hugging Face token
headers = {"Authorization": f"Bearer {API_TOKEN}"}
def get_emotion(text):
response = requests.post(API_URL, headers=headers, json={"inputs": text})
response.raise_for_status()
predictions = response.json()
return predictions[0][0]["label"]
st.title("๐ŸŽฎ Emotion Guesser Game")
st.write("Type a sentence and guess the emotion!")
sentence = st.text_input("Enter your sentence:")
guess = st.text_input("Guess the emotion (joy, sadness, anger, fear, love, surprise):")
if st.button("Submit"):
if sentence and guess:
actual = get_emotion(sentence).lower()
guess = guess.lower()
if guess == actual:
st.success("โœ… Correct!")
else:
st.error(f"โŒ Wrong! The correct emotion was: {actual}")