QAway-to commited on
Commit
995a334
·
1 Parent(s): c6e8312

New model. Qwen/Qwen2.5-1.5B-Instruct. v1.2

Browse files
Files changed (1) hide show
  1. app.py +14 -13
app.py CHANGED
@@ -70,37 +70,38 @@ def generate_first_question():
70
  return "What do you usually enjoy doing in your free time?"
71
 
72
  def analyze_and_ask(user_text, prev_count):
73
- """
74
- Основная логика: анализ MBTI + генерация нового вопроса.
75
- """
76
  if not user_text.strip():
77
  return "⚠️ Введите ответ.", "", prev_count
78
 
79
- # Прогресс
80
  try:
81
  n = int(prev_count.split("/")[0]) + 1
82
  except Exception:
83
  n = 1
84
  counter = f"{n}/30"
85
 
86
- # Анализ MBTI
87
  res = mbti_pipe(user_text)[0]
88
  res_sorted = sorted(res, key=lambda x: x["score"], reverse=True)
89
  mbti_text = "\n".join([f"{r['label']} → {r['score']:.3f}" for r in res_sorted[:3]])
90
 
91
- # Промпт для Qwen — чёткий, чтобы не возвращала инструкцию
92
  prompt = (
93
- f"User said: '{user_text}'.\n"
94
- "Generate exactly one short, natural, open-ended question about personality, emotions, or preferences. "
95
- "Avoid meta explanations, instructions, or introductions. "
96
- "Output only the plain question text without quotes or notes."
 
97
  )
98
 
99
- # Генерация нового вопроса
100
  raw = llm_pipe(prompt)[0]["generated_text"]
101
- question = clean_question(raw)
 
 
 
 
 
 
 
102
 
103
- return mbti_text, question, counter
104
 
105
  # ===============================================================
106
  # 3️⃣ Интерфейс Gradio
 
70
  return "What do you usually enjoy doing in your free time?"
71
 
72
  def analyze_and_ask(user_text, prev_count):
 
 
 
73
  if not user_text.strip():
74
  return "⚠️ Введите ответ.", "", prev_count
75
 
 
76
  try:
77
  n = int(prev_count.split("/")[0]) + 1
78
  except Exception:
79
  n = 1
80
  counter = f"{n}/30"
81
 
 
82
  res = mbti_pipe(user_text)[0]
83
  res_sorted = sorted(res, key=lambda x: x["score"], reverse=True)
84
  mbti_text = "\n".join([f"{r['label']} → {r['score']:.3f}" for r in res_sorted[:3]])
85
 
86
+ # Новый, уточнённый промпт
87
  prompt = (
88
+ f"User said: '{user_text}'. "
89
+ "Generate one natural, open-ended question that starts with 'What', 'Why', 'How', or 'When'. "
90
+ "Avoid rephrasing or quoting the user's text. "
91
+ "Do NOT explain what you are doing or include any instructions. "
92
+ "Output only the question itself."
93
  )
94
 
 
95
  raw = llm_pipe(prompt)[0]["generated_text"]
96
+ cleaned = clean_question(raw)
97
+
98
+ # Если вопрос не начинается с нужного слова — создаём fallback
99
+ valid_starts = ("What", "Why", "How", "When")
100
+ if not cleaned.startswith(valid_starts):
101
+ cleaned = "What motivates you to do the things you enjoy most?"
102
+
103
+ return mbti_text, cleaned, counter
104
 
 
105
 
106
  # ===============================================================
107
  # 3️⃣ Интерфейс Gradio