Spaces:
Sleeping
Sleeping
| import os | |
| import gradio as gr | |
| from openai import OpenAI | |
| client = OpenAI(api_key=os.getenv("OPENAI_API_KEY")) | |
| chat_history = [] | |
| def advisory_chatbot(user_input): | |
| try: | |
| chat_history.append({"role": "user", "content": user_input}) | |
| messages = [ | |
| {"role": "system", "content": | |
| "You are an educational and life advisor. Help users with:\n" | |
| "- Study planning\n" | |
| "- Finding universities\n" | |
| "- Locating scholarships\n" | |
| "- Creating daily routines\n" | |
| "- Answering general educational questions.\n" | |
| "Be helpful, friendly, and proactive."} | |
| ] + chat_history | |
| response = client.chat.completions.create( | |
| model="gpt-4", | |
| messages=messages, | |
| max_tokens=500, | |
| temperature=0.7 | |
| ) | |
| reply = response.choices[0].message.content | |
| chat_history.append({"role": "assistant", "content": reply}) | |
| return reply | |
| except Exception as e: | |
| return f"⚠️ Error: {str(e)}" | |
| iface = gr.Interface( | |
| fn=advisory_chatbot, | |
| inputs=gr.Textbox(lines=3, placeholder="Ask about study tips, universities, scholarships...", label="Your Question"), | |
| outputs=gr.Textbox(label="Advisor's Response"), | |
| title="📚 Study & Scholarship Advisory Chatbot", | |
| description="Ask about study advice, finding universities, scholarship options, routine planning, and general education questions.", | |
| theme="compact" | |
| ) | |
| iface.launch() | |