Spaces:
Sleeping
Sleeping
| import os | |
| import gradio as gr | |
| from openai import OpenAI | |
| # Подключение к OpenRouter | |
| client = OpenAI( | |
| base_url="https://openrouter.ai/api/v1", | |
| api_key=os.getenv("OPENROUTER_API_KEY") | |
| ) | |
| SYSTEM_PROMPT = """ | |
| You are a professional job interview simulator. | |
| You act as an HR interviewer. | |
| Rules: | |
| - Ask one question at a time. | |
| - Wait for the user's answer. | |
| - After 5 questions, provide structured feedback: | |
| - Strengths | |
| - Weaknesses | |
| - Final recommendation | |
| Be realistic and professional. | |
| """ | |
| def chat_with_ai(message, history): | |
| messages = [{"role": "system", "content": SYSTEM_PROMPT}] | |
| for human, assistant in history: | |
| messages.append({"role": "user", "content": human}) | |
| messages.append({"role": "assistant", "content": assistant}) | |
| messages.append({"role": "user", "content": message}) | |
| response = client.chat.completions.create( | |
| model="anthropic/claude-3.5-sonnet", | |
| messages=messages, | |
| temperature=0.7 | |
| ) | |
| reply = response.choices[0].message.content | |
| return reply | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# 🎯 InterviewSim AI") | |
| gr.Markdown("Simulate a real job interview and receive feedback.") | |
| chatbot = gr.ChatInterface( | |
| chat_with_ai, | |
| textbox=gr.Textbox(placeholder="Type your answer here...", container=False), | |
| title="AI Interviewer" | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |