Download app.py from faiz3123/CodeDay: direct link, hf CLI and curl.
- Browser
- Download file 8.55 kB
-
https://huggingface.co/spaces/faiz3123/CodeDay/resolve/main/app.py
- Command line
-
hf download hf://spaces/faiz3123/CodeDay/app.py
-
curl -L -o app.py https://huggingface.co/spaces/faiz3123/CodeDay/resolve/main/app.py
8.55 kB
| import streamlit as st | |
| import random | |
| # Set page config | |
| st.set_page_config(page_title="Emoji Detective", page_icon="๐ต๏ธ", layout="centered") | |
| # Emoji mapping function | |
| def get_emoji(score): | |
| if score >= 50: | |
| return "๐คฉ" # Star-struck face (ecstatic) | |
| elif 30 <= score < 10: | |
| return "๐" # Smiling face with open mouth (very happy) | |
| elif 10 <= score < 30: | |
| return "๐" # Grinning face (happy) | |
| elif 0 <= score < 10: | |
| return "๐" # Slightly smiling face (content) | |
| elif -10 <= score < 0: | |
| return "๐" # Confused face (neutral) | |
| elif -20 <= score < -10: | |
| return "๐" # Slightly frowning face (sad) | |
| elif -25 <= score < -20: | |
| return "๐ข" # Crying face (very sad) | |
| elif -30 <= score < -25: | |
| return "๐ญ" # Loudly crying face (heartbroken) | |
| else: | |
| return "๐ฑ" # Face screaming in fear (game over) | |
| # Initialize points, wrong attempts, and mysteries | |
| if 'points' not in st.session_state: | |
| st.session_state.points = 10 # Start with 10 points | |
| if 'wrong_attempts' not in st.session_state: | |
| st.session_state.wrong_attempts = 0 | |
| if 'mysteries' not in st.session_state: | |
| st.session_state.mysteries = [ | |
| {"clue": "๐ฆ๐", "hint": "A story about a lion becoming king.", "answer": "Lion King"}, | |
| #{"clue": "๐ญ๐ฐ", "hint": "A mouse loves to cook in a restaurant.", "answer": "Ratatouille"}, | |
| {"clue": "๐ธโ๏ธ", "hint": "A princess with ice powers.", "answer": "Frozen"}, | |
| {"clue": "๐๐", "hint": "A clownfish looking for his son.", "answer": "Finding Nemo"}, | |
| # {"clue": "๐๐ฆ", "hint": "A boy trains a dragon.", "answer": "How to Train Your Dragon"}, | |
| {"clue": "๐๐จโ๐", "hint": "Toys go on a space adventure.", "answer": "Toy Story"}, | |
| # {"clue": "๐ป๐ฏ", "hint": "A bear who loves honey.", "answer": "Winnie the Pooh"}, | |
| #{"clue": "๐ฆ๐ฆ", "hint": "A park full of dinosaurs.", "answer": "Jurassic Park"}, | |
| {"clue": "๐งโโ๏ธโก", "hint": "A boy wizard goes to magic school.", "answer": "Harry Potter"}, | |
| #{"clue": "๐ธ๐ธ", "hint": "A princess kisses a frog.", "answer": "The Princess and the Frog"}, | |
| # {"clue": "๐๐", "hint": "A caterpillar eats lots of food.", "answer": "The Very Hungry Caterpillar"}, | |
| {"clue": "๐๐บ", "hint": "A girl sails to save her island.", "answer": "Moana"}, | |
| {"clue": "๐พ๐", "hint": "Pups solving mysteries together.", "answer": "Paw Patrol"}, | |
| #{"clue": "๐ฆธโโ๏ธ๐ฆธโโ๏ธ", "hint": "A superhero family saves the world.", "answer": "The Incredibles"}, | |
| {"clue": "๐ฆ๐", "hint": "Animals escape from a zoo.", "answer": "Madagascar"}, | |
| #{"clue": "๐๐ง", "hint": "A mouse wants to become a chef.", "answer": "Ratatouille"}, | |
| {"clue": "๐ฐ๐ต๏ธโโ๏ธ", "hint": "A bunny cop solves a case.", "answer": "Zootopia"}, | |
| #{"clue": "๐ดโโ๏ธ๐", "hint": "A boy meets an alien who wants to go home.", "answer": "E.T."}, | |
| #{"clue": "๐ข๐ฅ", "hint": "Turtles fight crime using ninja skills.", "answer": "Teenage Mutant Ninja Turtles"}, | |
| {"clue": "๐ฉโ๐ณ๐", "hint": "A girl and a dog share a spaghetti kiss.", "answer": "Lady and the Tramp"}, | |
| {"clue": "๐ ๐", "hint": "A girl loses her glass slipper.", "answer": "Cinderella"}, | |
| {"clue": "๐ฆ๐ณ", "hint": "A boy and a tree become lifelong friends.", "answer": "The Giving Tree"}, | |
| #{"clue": "๐ฆ๐ป", "hint": "A clever fox outsmarts everyone.", "answer": "Fantastic Mr. Fox"}, | |
| {"clue": "๐๐", "hint": "A house flies with balloons.", "answer": "Up"}, | |
| #{"clue": "๐พ๐ฏ", "hint": "A little bear and tiger go exploring.", "answer": "Winnie the Pooh"}, | |
| {"clue": "๐ฐ๐น", "hint": "A girl falls in love with a beast.", "answer": "Beauty and the Beast"}, | |
| # {"clue": "๐ฎ๐ญ", "hint": "A mouse helps make tacos.", "answer": "Dragons Love Tacos"}, | |
| {"clue": "๐งโโ๏ธ๐", "hint": "A genie grants three wishes.", "answer": "Aladdin"}, | |
| # {"clue": "๐๐", "hint": "Tiny heroes save their colony.", "answer": "A Bug's Life"}, | |
| #{"clue": "๐๐คก", "hint": "Clowns have a party with lots of balloons.", "answer": "The Greatest Showman"}, | |
| # {"clue": "๐ซ๐ญ", "hint": "Kids visit a magical chocolate factory.", "answer": "Charlie and the Chocolate Factory"}, | |
| # {"clue": "๐ฉโ๐๐", "hint": "A girl dreams of being an astronaut.", "answer": "Interstellar Dreams"}, | |
| {"clue": "๐ด๐", "hint": "A jungle boy and his animal friends.", "answer": "The Jungle Book"}, | |
| {"clue": "๐ฆ๐ค", "hint": "A bird learns how to sing.", "answer": "Rio"}, | |
| # {"clue": "๐ฆ๐", "hint": "Dinosaurs try to survive a volcanic eruption.", "answer": "The Land Before Time"}, | |
| {"clue": "๐ต๐น", "hint": "A girl follows her dreams to make music.", "answer": "Coco"}, | |
| #{"clue": "๐ฆ๐", "hint": "A little duckling finds its family.", "answer": "The Ugly Duckling"}, | |
| {"clue": "๐๐", "hint": "A space ranger defends the galaxy.", "answer": "Buzz Lightyear"}, | |
| {"clue": "๐งต๐", "hint": "A girl shows courage by saving her family.", "answer": "Mulan"}, | |
| {"clue": "๐ฆ๐ง", "hint": "Birds team up to build a giant nest.", "answer": "Angry Birds"}, | |
| # {"clue": "๐๐", "hint": "A jungle boy grows up with animals.", "answer": "The Jungle Book"}, | |
| # {"clue": "๐งโโ๏ธ๐ค", "hint": "A mermaid dreams of a new life.", "answer": "The Little Mermaid"}, | |
| # {"clue": "๐ฆข๐ป", "hint": "A swan learns to dance.", "answer": "Swan Lake"}, | |
| # {"clue": "๐ดโโ ๏ธโ", "hint": "A boy joins pirates on an adventure.", "answer": "Peter Pan"}, | |
| # {"clue": "๐๐ ", "hint": "A girl visits another magical world in red shoes.", "answer": "Wizard of Oz"}, | |
| # {"clue": "๐๐งโโ๏ธ", "hint": "A small hero fights to save Middle Earth.", "answer": "The Hobbit"}, | |
| # {"clue": "๐ฆ๐", "hint": "A reindeer helps save Christmas.", "answer": "Rudolph the Red-Nosed Reindeer"} | |
| ] | |
| if 'selected_mystery' not in st.session_state: | |
| st.session_state.selected_mystery = random.choice(st.session_state.mysteries) | |
| # Main game function | |
| def emoji_detective_game(): | |
| st.title("๐ต๏ธ Emoji Detective") | |
| st.write("Welcome, Detective! Decode the emoji clues to solve the mystery! Here you will be getting clues regarding the famous cartoons guess it") | |
| st.write(" For a correct answer you will be granted +10 ") | |
| st.write("For a wrong answer -8") | |
| st.write("When you skip the question -5") | |
| st.write(f"Your current happiness score: {st.session_state.points} {get_emoji(st.session_state.points)}") | |
| # Current mystery | |
| selected_mystery = st.session_state.selected_mystery | |
| st.subheader(f"Clue: {selected_mystery['clue']}") | |
| # Provide a hint | |
| if st.button("Get a hint ๐ต"): | |
| st.info(f"Hint: {selected_mystery['hint']}") | |
| # User input | |
| user_answer = st.text_input("Your Answer", "").strip().lower() | |
| # Check answer | |
| if st.button("Submit Answer"): | |
| if user_answer == selected_mystery['answer'].lower(): | |
| st.session_state.points += 10 | |
| st.success("๐ Correct! You've solved the mystery!") | |
| st.balloons() | |
| st.session_state.wrong_attempts = 0 | |
| st.session_state.selected_mystery = random.choice(st.session_state.mysteries) | |
| else: | |
| st.session_state.wrong_attempts += 1 | |
| if st.session_state.wrong_attempts >= 3: | |
| st.session_state.points -= 8 | |
| st.warning("โ ๏ธ You've made 3 wrong attempts! Moving to the next mystery.") | |
| st.session_state.wrong_attempts = 0 | |
| st.session_state.selected_mystery = random.choice(st.session_state.mysteries) | |
| else: | |
| st.error("Wrong answer! Try again.") | |
| # Skip question | |
| if st.button("Skip ๐"): | |
| st.session_state.points -= 5 | |
| st.warning("โ ๏ธ You skipped the question! Points deducted.") | |
| st.session_state.wrong_attempts = 0 | |
| st.session_state.selected_mystery = random.choice(st.session_state.mysteries) | |
| # Display points in the sidebar | |
| st.sidebar.write(f"Your Points: {st.session_state.points} {get_emoji(st.session_state.points)}") | |
| # Main app function | |
| def main(): | |
| emoji_detective_game() | |
| if __name__ == "__main__": | |
| main() |