|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|