Spaces:
Runtime error
Runtime error
| 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}") | |