File size: 2,122 Bytes
1ef591c a8bca78 dd7e39b ac25eb6 a8bca78 ac25eb6 a8bca78 a9ecae7 3dff80d a8bca78 3dff80d a9ecae7 a8bca78 a9ecae7 a8bca78 ac25eb6 a8bca78 c8cd73e ac25eb6 7fa6779 ac25eb6 a9ecae7 a8bca78 dd7e39b 97efcfb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import gradio as gr
import asyncio
from core.utils import generate_first_question
from core.mbti_analyzer import analyze_mbti
from core.interviewer import generate_question
# ===============================================================
# 3️⃣ Интерфейс Gradio
# ===============================================================
async def analyze_and_ask_async(user_text, prev_count, user_id="default_user"):
if not user_text.strip():
return "⚠️ Введите ответ.", "", prev_count
try:
n = int(prev_count.split("/")[0]) + 1
except Exception:
n = 1
counter = f"{n}/30"
mbti_task = asyncio.create_task(analyze_mbti(user_text))
interviewer_task = asyncio.create_task(generate_question(user_id, user_text))
mbti_text, next_question = await asyncio.gather(mbti_task, interviewer_task)
return mbti_text, next_question, counter
with gr.Blocks(theme=gr.themes.Soft(), title="MBTI Personality Interviewer") as demo:
gr.Markdown(
"## 🧠 MBTI Personality Interviewer\n"
"Определи личностный тип и получи следующий вопрос от интервьюера."
)
with gr.Row():
with gr.Column(scale=1):
inp = gr.Textbox(
label="Ваш ответ",
placeholder="Например: I enjoy working with people and organizing events.",
lines=4
)
btn = gr.Button("Анализировать и задать новый вопрос", variant="primary")
with gr.Column(scale=1):
mbti_out = gr.Textbox(label="📊 Анализ MBTI", lines=4)
interviewer_out = gr.Textbox(label="💬 Следующий вопрос от интервьюера", lines=3)
progress = gr.Textbox(label="⏳ Прогресс", value="0/30")
btn.click(analyze_and_ask_async, inputs=[inp, progress], outputs=[mbti_out, interviewer_out, progress])
demo.load(lambda: ("", generate_first_question(), "0/30"), None, [mbti_out, interviewer_out, progress])
demo.launch()
|