Update app.py
Browse files
app.py
CHANGED
|
@@ -9,9 +9,9 @@ For more information on `huggingface_hub` Inference API support, please check th
|
|
| 9 |
#client = InferenceClient("DrDomedag/LocoLama")
|
| 10 |
#client = InferenceClient("unsloth/llama-3.2-1b-instruct-bnb-4bit")
|
| 11 |
#client = InferenceClient("unsloth/llama-3.2-1b-bnb-4bit")
|
| 12 |
-
|
| 13 |
#client = InferenceClient("unsloth/Llama-3.2-3B-Instruct") # Works!
|
| 14 |
-
client = InferenceClient("DrDomedag/LocoLamav2")
|
| 15 |
#client = InferenceClient("T3lli/lora_model")
|
| 16 |
|
| 17 |
|
|
@@ -54,7 +54,7 @@ words = [
|
|
| 54 |
|
| 55 |
class WordGame:
|
| 56 |
|
| 57 |
-
def __init__(self):
|
| 58 |
self.points = 0
|
| 59 |
self.target_word = ""
|
| 60 |
self.attempts = 3
|
|
@@ -69,6 +69,8 @@ class WordGame:
|
|
| 69 |
if self.target_word in string:
|
| 70 |
print(f"The player input the target word and the task was reset.")
|
| 71 |
self.generate_task()
|
|
|
|
|
|
|
| 72 |
else:
|
| 73 |
print(f"The player did not input the target word, so that's good.")
|
| 74 |
|
|
@@ -77,7 +79,9 @@ class WordGame:
|
|
| 77 |
if self.target_word in string:
|
| 78 |
self.points += self.attempts
|
| 79 |
print(f"The player scored {self.attempts} points and has a total of {self.points}.")
|
|
|
|
| 80 |
self.generate_task()
|
|
|
|
| 81 |
else:
|
| 82 |
print("The response did not contain the word.")
|
| 83 |
self.attempts -= 1
|
|
@@ -85,11 +89,15 @@ class WordGame:
|
|
| 85 |
if self.attempts <= 0:
|
| 86 |
self.generate_task()
|
| 87 |
print(f"The player ran out of attempts.")
|
|
|
|
| 88 |
else:
|
| 89 |
print(f"The player has attempts left.")
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
|
| 92 |
-
|
| 93 |
|
| 94 |
|
| 95 |
|
|
@@ -138,6 +146,7 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
| 138 |
"""
|
| 139 |
demo = gr.ChatInterface(
|
| 140 |
respond,
|
|
|
|
| 141 |
additional_inputs=[
|
| 142 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 143 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
|
@@ -152,6 +161,8 @@ demo = gr.ChatInterface(
|
|
| 152 |
],
|
| 153 |
)
|
| 154 |
|
|
|
|
|
|
|
| 155 |
|
| 156 |
if __name__ == "__main__":
|
| 157 |
demo.launch()
|
|
|
|
| 9 |
#client = InferenceClient("DrDomedag/LocoLama")
|
| 10 |
#client = InferenceClient("unsloth/llama-3.2-1b-instruct-bnb-4bit")
|
| 11 |
#client = InferenceClient("unsloth/llama-3.2-1b-bnb-4bit")
|
| 12 |
+
client = InferenceClient("unsloth/Llama-3.2-1B-Instruct") # Works!
|
| 13 |
#client = InferenceClient("unsloth/Llama-3.2-3B-Instruct") # Works!
|
| 14 |
+
#client = InferenceClient("DrDomedag/LocoLamav2")
|
| 15 |
#client = InferenceClient("T3lli/lora_model")
|
| 16 |
|
| 17 |
|
|
|
|
| 54 |
|
| 55 |
class WordGame:
|
| 56 |
|
| 57 |
+
def __init__(self, ui):
|
| 58 |
self.points = 0
|
| 59 |
self.target_word = ""
|
| 60 |
self.attempts = 3
|
|
|
|
| 69 |
if self.target_word in string:
|
| 70 |
print(f"The player input the target word and the task was reset.")
|
| 71 |
self.generate_task()
|
| 72 |
+
self.points -= 1
|
| 73 |
+
self.update_status(message="You input the target word yourself, so you lost one point and the game reset.")
|
| 74 |
else:
|
| 75 |
print(f"The player did not input the target word, so that's good.")
|
| 76 |
|
|
|
|
| 79 |
if self.target_word in string:
|
| 80 |
self.points += self.attempts
|
| 81 |
print(f"The player scored {self.attempts} points and has a total of {self.points}.")
|
| 82 |
+
score_gained = self.attempts
|
| 83 |
self.generate_task()
|
| 84 |
+
self.update_status(message=f"Success! You earned {score_gained} points!")
|
| 85 |
else:
|
| 86 |
print("The response did not contain the word.")
|
| 87 |
self.attempts -= 1
|
|
|
|
| 89 |
if self.attempts <= 0:
|
| 90 |
self.generate_task()
|
| 91 |
print(f"The player ran out of attempts.")
|
| 92 |
+
self.update_status(message=f"You did not win in three attempts. Generating new target word.")
|
| 93 |
else:
|
| 94 |
print(f"The player has attempts left.")
|
| 95 |
+
|
| 96 |
+
def update_status(self, message=""):
|
| 97 |
+
demo.title = f'Current score: {self.points}, remaining attempts: {self.attempts}, target word: "{self.target_word}" {message}'
|
| 98 |
|
| 99 |
|
| 100 |
+
|
| 101 |
|
| 102 |
|
| 103 |
|
|
|
|
| 146 |
"""
|
| 147 |
demo = gr.ChatInterface(
|
| 148 |
respond,
|
| 149 |
+
title="Hi Elli",
|
| 150 |
additional_inputs=[
|
| 151 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 152 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
|
|
|
| 161 |
],
|
| 162 |
)
|
| 163 |
|
| 164 |
+
game = WordGame(demo)
|
| 165 |
+
|
| 166 |
|
| 167 |
if __name__ == "__main__":
|
| 168 |
demo.launch()
|