Delete kasoti_brain.py
Browse files- kasoti_brain.py +0 -38
kasoti_brain.py
DELETED
|
@@ -1,38 +0,0 @@
|
|
| 1 |
-
from transformers import pipeline
|
| 2 |
-
|
| 3 |
-
class KasotiGame:
|
| 4 |
-
def __init__(self):
|
| 5 |
-
# Use a smaller model (GPT-2 in this case)
|
| 6 |
-
self.qa_model = pipeline("text-generation", model="gpt2", device=0)
|
| 7 |
-
self.questions = []
|
| 8 |
-
self.answers = []
|
| 9 |
-
self.index = 0
|
| 10 |
-
self.max_questions = 20
|
| 11 |
-
|
| 12 |
-
def current_question(self):
|
| 13 |
-
if self.index < len(self.questions):
|
| 14 |
-
return self.questions[self.index]
|
| 15 |
-
return "Let me make a guess..."
|
| 16 |
-
|
| 17 |
-
def generate_next_question(self):
|
| 18 |
-
history = "\n".join([f"Q: {q} A: {a}" for q, a in zip(self.questions, self.answers)])
|
| 19 |
-
prompt = f"You are playing a game where the user thinks of an object, person, or place. Ask a smart yes/no question to narrow it down. Here's the history:\n{history}\nNext question:"
|
| 20 |
-
response = self.qa_model(prompt, max_length=50, do_sample=True)[0]['generated_text']
|
| 21 |
-
question = response.split("Next question:")[-1].strip().split("\n")[0]
|
| 22 |
-
return question
|
| 23 |
-
|
| 24 |
-
def update_answer(self, answer):
|
| 25 |
-
if self.index < len(self.questions):
|
| 26 |
-
self.answers.append(answer)
|
| 27 |
-
if self.index < self.max_questions:
|
| 28 |
-
question = self.generate_next_question()
|
| 29 |
-
self.questions.append(question)
|
| 30 |
-
self.index += 1
|
| 31 |
-
return question
|
| 32 |
-
return "Game over!"
|
| 33 |
-
|
| 34 |
-
def next_question(self):
|
| 35 |
-
return self.questions[self.index - 1] if self.questions else self.generate_next_question()
|
| 36 |
-
|
| 37 |
-
def status(self):
|
| 38 |
-
return f"Questions Asked: {self.index}/{self.max_questions}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|