gouravgujariya commited on
Commit
e92b92d
Β·
verified Β·
1 Parent(s): 4f48e66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -18,8 +18,10 @@ def reset_game():
18
  # Ask LLM for the first emoji puzzle
19
  emoji_prompt = "Give me an emoji-based puzzle for a word or phrase guessing game."
20
  response = pipe([{"role": "user", "content": emoji_prompt}], max_new_tokens=30)
21
- current_emoji = response[0]['generated_text'].strip()
22
 
 
 
 
23
  # Return introduction and the emoji puzzle
24
  return introduction + f"Here's your first puzzle: {current_emoji}"
25
 
@@ -47,10 +49,12 @@ def emoji_game(user_input=""):
47
  # Check if the user made a guess; LLM evaluates the guess
48
  guess_prompt = f"User guessed '{user_input}'. Was the guess correct for this emoji puzzle: {current_emoji}?"
49
  response = pipe([{"role": "user", "content": guess_prompt}], max_new_tokens=30)
50
- response_text = response[0]['generated_text'].strip().lower()
51
 
 
 
 
52
  # Process response: if it's correct, increase points; otherwise, decrease points
53
- if "correct" in response_text: # Correct guess
54
  points += 1
55
  if points >= 10:
56
  return f"πŸŽ‰ Correct! You've reached 10 points! You win the game! πŸ†"
@@ -58,7 +62,9 @@ def emoji_game(user_input=""):
58
  # Get next emoji puzzle for the user
59
  next_emoji_prompt = "Give me another emoji-based puzzle."
60
  response = pipe([{"role": "user", "content": next_emoji_prompt}], max_new_tokens=30)
61
- current_emoji = response[0]['generated_text'].strip()
 
 
62
  return f"βœ… Correct! Your current points: {points}. Here's your next puzzle: {current_emoji}"
63
  else: # Incorrect guess
64
  points -= 1
 
18
  # Ask LLM for the first emoji puzzle
19
  emoji_prompt = "Give me an emoji-based puzzle for a word or phrase guessing game."
20
  response = pipe([{"role": "user", "content": emoji_prompt}], max_new_tokens=30)
 
21
 
22
+ # Ensure to get the generated text correctly
23
+ current_emoji = response[0]['generated_text'] if response and isinstance(response, list) and len(response) > 0 else "❓"
24
+
25
  # Return introduction and the emoji puzzle
26
  return introduction + f"Here's your first puzzle: {current_emoji}"
27
 
 
49
  # Check if the user made a guess; LLM evaluates the guess
50
  guess_prompt = f"User guessed '{user_input}'. Was the guess correct for this emoji puzzle: {current_emoji}?"
51
  response = pipe([{"role": "user", "content": guess_prompt}], max_new_tokens=30)
 
52
 
53
+ # Ensure to get the generated text correctly
54
+ response_text = response[0]['generated_text'] if response and isinstance(response, list) and len(response) > 0 else "❓"
55
+
56
  # Process response: if it's correct, increase points; otherwise, decrease points
57
+ if "correct" in response_text.lower(): # Correct guess
58
  points += 1
59
  if points >= 10:
60
  return f"πŸŽ‰ Correct! You've reached 10 points! You win the game! πŸ†"
 
62
  # Get next emoji puzzle for the user
63
  next_emoji_prompt = "Give me another emoji-based puzzle."
64
  response = pipe([{"role": "user", "content": next_emoji_prompt}], max_new_tokens=30)
65
+
66
+ # Ensure to get the generated text correctly
67
+ current_emoji = response[0]['generated_text'] if response and isinstance(response, list) and len(response) > 0 else "❓"
68
  return f"βœ… Correct! Your current points: {points}. Here's your next puzzle: {current_emoji}"
69
  else: # Incorrect guess
70
  points -= 1