Spaces:
Runtime error
Runtime error
gouravgujariya
commited on
Commit
•
7952d76
1
Parent(s):
355ccec
Update app.py
Browse files
app.py
CHANGED
@@ -22,20 +22,33 @@ def reset_game():
|
|
22 |
|
23 |
return introduction + f"Here's your first puzzle: {current_emoji}"
|
24 |
|
25 |
-
# Function to handle the game logic
|
26 |
-
def emoji_game(
|
27 |
global points, current_emoji
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
# If no user input (game start), LLM asks the question first
|
30 |
-
if
|
31 |
return reset_game()
|
32 |
|
33 |
# Check if the user made a guess; LLM evaluates the guess
|
34 |
-
guess_prompt = f"User guessed '{
|
35 |
response = pipe([{"role": "user", "content": guess_prompt}])
|
36 |
response_text = response[0]['generated_text'].lower()
|
37 |
|
38 |
-
# Process response: if it's correct, increase points
|
39 |
if "correct" in response_text: # Correct guess
|
40 |
points += 1
|
41 |
if points >= 10:
|
|
|
22 |
|
23 |
return introduction + f"Here's your first puzzle: {current_emoji}"
|
24 |
|
25 |
+
# Function to handle the game logic and user interactions
|
26 |
+
def emoji_game(user_input=""):
|
27 |
global points, current_emoji
|
28 |
|
29 |
+
# Normalize the user input
|
30 |
+
user_input = user_input.strip().lower()
|
31 |
+
|
32 |
+
# Handle specific phrases from the user
|
33 |
+
if user_input in ["hi", "hello"]:
|
34 |
+
return "Hello! Ready to play 'Guess the Word from Emojis'? Type your guess or ask for a hint!"
|
35 |
+
elif user_input in ["how does the game work?", "can you explain the rules?", "how do I play?"]:
|
36 |
+
return "In this game, you'll guess the word or phrase based on emojis. For each correct guess, you earn 1 point. If you guess wrong, you lose 1 point. Reach 10 points to win or drop to -10 points to lose!"
|
37 |
+
elif user_input in ["give me a hint", "i need a hint"]:
|
38 |
+
# Provide a hint (a simple example could be the length of the answer)
|
39 |
+
hint = f"The word or phrase has {len(current_emoji)} characters."
|
40 |
+
return f"Hint: {hint}"
|
41 |
+
|
42 |
# If no user input (game start), LLM asks the question first
|
43 |
+
if user_input == "":
|
44 |
return reset_game()
|
45 |
|
46 |
# Check if the user made a guess; LLM evaluates the guess
|
47 |
+
guess_prompt = f"User guessed '{user_input}'. Was the guess correct for this emoji puzzle: {current_emoji}?"
|
48 |
response = pipe([{"role": "user", "content": guess_prompt}])
|
49 |
response_text = response[0]['generated_text'].lower()
|
50 |
|
51 |
+
# Process response: if it's correct, increase points; otherwise, decrease points
|
52 |
if "correct" in response_text: # Correct guess
|
53 |
points += 1
|
54 |
if points >= 10:
|