QAway-to commited on
Commit
3462c0f
·
1 Parent(s): 916e292

Back to normal app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -12
app.py CHANGED
@@ -1,10 +1,17 @@
1
- # app.py
2
- import gradio as gr
3
  import asyncio
 
4
  from core.utils import generate_first_question
5
  from core.mbti_analyzer import analyze_mbti
6
  from core.interviewer import generate_next_question
7
 
 
 
 
 
 
 
 
 
8
  async def analyze_and_ask(user_text, prev_count, user_id="default_user"):
9
  if not user_text.strip():
10
  return "⚠️ Введите ответ.", "", prev_count
@@ -15,12 +22,10 @@ async def analyze_and_ask(user_text, prev_count, user_id="default_user"):
15
  n = 1
16
  counter = f"{n}/16"
17
 
18
- # Анализ MBTI
19
  mbti_text = ""
20
  for part in analyze_mbti(user_text):
21
  mbti_text = part
22
 
23
- # Генерация вопроса
24
  next_q_data = await generate_next_question(user_id, user_text)
25
  if next_q_data["completed"]:
26
  next_question = "✅ Interview finished! All 16 personality categories covered."
@@ -30,26 +35,24 @@ async def analyze_and_ask(user_text, prev_count, user_id="default_user"):
30
  return mbti_text, next_question, counter
31
 
32
 
 
33
  with gr.Blocks(theme=gr.themes.Soft(), title="MBTI Interviewer AI") as demo:
34
  gr.Markdown("## 🧠 MBTI Personality Interviewer\nАнализ и вопросы по 16 категориям MBTI.")
35
 
36
  with gr.Row():
37
  with gr.Column(scale=1):
38
- inp = gr.Textbox(
39
- label="Ваш ответ",
40
- placeholder="Например: I enjoy organizing group projects.",
41
- lines=4
42
- )
43
  btn = gr.Button("Отправить", variant="primary")
44
  with gr.Column(scale=1):
45
  mbti_out = gr.Textbox(label="📊 Анализ MBTI", lines=4)
46
  interviewer_out = gr.Textbox(label="💬 Следующий вопрос", lines=3)
47
  progress = gr.Textbox(label="⏳ Прогресс", value="0/16")
48
 
49
- btn.click(analyze_and_ask, inputs=[inp, progress], outputs=[mbti_out, interviewer_out, progress])
 
50
 
51
- demo.load(lambda: ("", generate_first_question(), "0/16"), inputs=None, outputs=[mbti_out, interviewer_out, progress])
 
52
 
53
  if __name__ == "__main__":
54
-
55
  demo.launch()
 
 
 
1
  import asyncio
2
+ import gradio as gr
3
  from core.utils import generate_first_question
4
  from core.mbti_analyzer import analyze_mbti
5
  from core.interviewer import generate_next_question
6
 
7
+
8
+ # ---- Адаптер ----
9
+ def analyze_and_ask_sync(user_text, prev_count, user_id="default_user"):
10
+ """Синхронный адаптер для Gradio"""
11
+ return asyncio.run(analyze_and_ask(user_text, prev_count, user_id))
12
+
13
+
14
+ # ---- Асинхронная логика ----
15
  async def analyze_and_ask(user_text, prev_count, user_id="default_user"):
16
  if not user_text.strip():
17
  return "⚠️ Введите ответ.", "", prev_count
 
22
  n = 1
23
  counter = f"{n}/16"
24
 
 
25
  mbti_text = ""
26
  for part in analyze_mbti(user_text):
27
  mbti_text = part
28
 
 
29
  next_q_data = await generate_next_question(user_id, user_text)
30
  if next_q_data["completed"]:
31
  next_question = "✅ Interview finished! All 16 personality categories covered."
 
35
  return mbti_text, next_question, counter
36
 
37
 
38
+ # ---- Gradio UI ----
39
  with gr.Blocks(theme=gr.themes.Soft(), title="MBTI Interviewer AI") as demo:
40
  gr.Markdown("## 🧠 MBTI Personality Interviewer\nАнализ и вопросы по 16 категориям MBTI.")
41
 
42
  with gr.Row():
43
  with gr.Column(scale=1):
44
+ inp = gr.Textbox(label="Ваш ответ", placeholder="Например: I enjoy organizing group projects.", lines=4)
 
 
 
 
45
  btn = gr.Button("Отправить", variant="primary")
46
  with gr.Column(scale=1):
47
  mbti_out = gr.Textbox(label="📊 Анализ MBTI", lines=4)
48
  interviewer_out = gr.Textbox(label="💬 Следующий вопрос", lines=3)
49
  progress = gr.Textbox(label="⏳ Прогресс", value="0/16")
50
 
51
+ # Здесь вызываем адаптер
52
+ btn.click(analyze_and_ask_sync, inputs=[inp, progress], outputs=[mbti_out, interviewer_out, progress])
53
 
54
+ demo.load(lambda: ("", generate_first_question(), "0/16"),
55
+ inputs=None, outputs=[mbti_out, interviewer_out, progress])
56
 
57
  if __name__ == "__main__":
 
58
  demo.launch()