Initial commit.
Browse files- app.py +10 -1
- wordgame.py +57 -0
- words.py +34 -0
app.py
CHANGED
@@ -1,7 +1,10 @@
|
|
1 |
import streamlit as st
|
2 |
from huggingface_hub import InferenceClient
|
3 |
-
import random
|
4 |
|
|
|
|
|
|
|
|
|
5 |
|
6 |
st.title("ChatGPT-like clone")
|
7 |
|
@@ -38,6 +41,12 @@ if st.button("Send"):
|
|
38 |
# Add the model's reply to the chat history
|
39 |
st.session_state.messages.append({"role": "assistant", "content": assistant_reply})
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
# Clear the input box
|
42 |
#st.session_state.user_input = ""
|
43 |
|
|
|
1 |
import streamlit as st
|
2 |
from huggingface_hub import InferenceClient
|
|
|
3 |
|
4 |
+
from wordgame import WordGame
|
5 |
+
|
6 |
+
|
7 |
+
wordgame = WordGame()
|
8 |
|
9 |
st.title("ChatGPT-like clone")
|
10 |
|
|
|
41 |
# Add the model's reply to the chat history
|
42 |
st.session_state.messages.append({"role": "assistant", "content": assistant_reply})
|
43 |
|
44 |
+
if not wordgame.check_input_for_word(user_input.strip().lower()):
|
45 |
+
check_result = wordgame.check_output_for_word(response)
|
46 |
+
st.session_state.messages.append({"role": "assistant", "content": check_result})
|
47 |
+
st.session_state.messages.append({"role": "assistant", "content": wordgame.update_status()})
|
48 |
+
|
49 |
+
|
50 |
# Clear the input box
|
51 |
#st.session_state.user_input = ""
|
52 |
|
wordgame.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
from words import words
|
3 |
+
|
4 |
+
class WordGame:
|
5 |
+
|
6 |
+
def __init__(self, chatbot):
|
7 |
+
self.points = 0
|
8 |
+
self.target_word = ""
|
9 |
+
self.attempts = 3
|
10 |
+
self.chatbot = chatbot
|
11 |
+
self.generate_task()
|
12 |
+
|
13 |
+
def generate_task(self):
|
14 |
+
self.attempts = 3
|
15 |
+
self.target_word = random.choice(words)
|
16 |
+
# print(f"New target word: {self.target_word}")
|
17 |
+
return self.target_word
|
18 |
+
|
19 |
+
def check_input_for_word(self, string):
|
20 |
+
if self.target_word in string.lower():
|
21 |
+
# print(f"The player input the target word and the task was reset.")
|
22 |
+
self.generate_task()
|
23 |
+
self.points -= 1
|
24 |
+
# self.update_status(message="You input the target word yourself, so you lost one point and the game reset.")
|
25 |
+
return True
|
26 |
+
|
27 |
+
else:
|
28 |
+
# print(f"The player did not input the target word, so that's good.")
|
29 |
+
return False
|
30 |
+
|
31 |
+
def check_output_for_word(self, string):
|
32 |
+
# print(f"Checking for '{self.target_word}' in '{string}'.")
|
33 |
+
if self.target_word in string.lower():
|
34 |
+
self.points += self.attempts
|
35 |
+
# print(f"The player scored {self.attempts} points and has a total of {self.points}.")
|
36 |
+
score_gained = self.attempts
|
37 |
+
self.generate_task()
|
38 |
+
return f"Success! You earned {score_gained} points!"
|
39 |
+
# self.update_status(message=f"Success! You earned {score_gained} points!")
|
40 |
+
else:
|
41 |
+
# print("The response did not contain the word.")
|
42 |
+
self.attempts -= 1
|
43 |
+
# print(f"Remaining attempts: {self.attempts}")
|
44 |
+
if self.attempts <= 0:
|
45 |
+
self.generate_task()
|
46 |
+
# print(f"The player ran out of attempts.")
|
47 |
+
return f"You did not win in three attempts. Generating new target word."
|
48 |
+
# self.update_status(message=f"You did not win in three attempts. Generating new target word.")
|
49 |
+
else:
|
50 |
+
# print(f"The player has attempts left.")
|
51 |
+
return "That didn't quite hit the mark. Try again!"
|
52 |
+
|
53 |
+
def update_status(self, message=""):
|
54 |
+
# gr.ChatInterface.update(title=f'The Game - Current score: {self.points}, remaining attempts: {self.attempts}, target word: "{self.target_word}" {message}')
|
55 |
+
self.chatbot.update(
|
56 |
+
title=f'The Game - Current score: {self.points}, remaining attempts: {self.attempts}, target word: "{self.target_word}" {message}')
|
57 |
+
return f'Current score: {self.points}, remaining attempts: {self.attempts}, target word: "{self.target_word}" {message}'
|
words.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
words = [
|
2 |
+
# Nouns (250)
|
3 |
+
"apple", "bridge", "cat", "door", "engine", "forest", "giraffe", "horizon", "island", "jungle",
|
4 |
+
"kite", "lake", "mountain", "notebook", "ocean", "penguin", "quartz", "rainbow", "snowflake", "tornado",
|
5 |
+
"umbrella", "village", "waterfall", "xylophone", "yard", "zebra", "actor", "ball", "camera", "desert",
|
6 |
+
"elephant", "firefly", "garden", "hat", "igloo", "jacket", "key", "lantern", "mirror", "necklace",
|
7 |
+
"owl", "piano", "quiver", "rocket", "squirrel", "trophy", "unicorn", "vase", "window", "yacht",
|
8 |
+
# ... Add more nouns to total 250
|
9 |
+
|
10 |
+
# Adjectives (250)
|
11 |
+
"brave", "calm", "delightful", "eager", "fancy", "gentle", "happy", "innocent", "jolly", "kind",
|
12 |
+
"lively", "magnificent", "noble", "optimistic", "peaceful", "quick", "radiant", "shy", "tidy", "unique",
|
13 |
+
"vivid", "warm", "yellow", "zealous", "adorable", "beautiful", "charming", "diligent", "energetic", "fierce",
|
14 |
+
"graceful", "humble", "intelligent", "jovial", "keen", "lovely", "merry", "neat", "outstanding", "pleasant",
|
15 |
+
"quirky", "respectful", "silly", "thoughtful", "upbeat", "vibrant", "whimsical", "youthful", "zany",
|
16 |
+
# ... Add more adjectives to total 250
|
17 |
+
|
18 |
+
# Verbs (250)
|
19 |
+
"accept", "bounce", "climb", "dance", "explore", "fly", "gather", "help", "imagine", "jump",
|
20 |
+
"kick", "laugh", "move", "notice", "open", "play", "question", "run", "sing", "talk",
|
21 |
+
"understand", "visit", "wait", "yell", "zoom", "answer", "build", "create", "dig", "enjoy",
|
22 |
+
"focus", "grow", "hunt", "identify", "juggle", "know", "learn", "measure", "negotiate", "observe",
|
23 |
+
"perform", "quiet", "record", "search", "travel", "update", "volunteer", "wander", "write",
|
24 |
+
# ... Add more verbs to total 250
|
25 |
+
|
26 |
+
# Adverbs (250)
|
27 |
+
"abruptly", "beautifully", "carefully", "diligently", "eagerly", "faithfully", "gracefully", "happily",
|
28 |
+
"immediately", "joyfully", "kindly", "loudly", "magically", "neatly", "openly", "politely", "quickly",
|
29 |
+
"rarely", "silently", "thoughtfully", "unexpectedly", "vividly", "warmly", "yawningly", "zealously",
|
30 |
+
"accidentally", "boldly", "cheerfully", "deliberately", "enthusiastically", "frequently", "gently", "honestly",
|
31 |
+
"intensely", "justly", "knowingly", "lightly", "merrily", "nervously", "officially", "partially", "quietly",
|
32 |
+
"readily", "safely", "terribly", "urgently", "vaguely", "wildly", "yearly", "zestfully",
|
33 |
+
# ... Add more adverbs to total 250
|
34 |
+
]
|