Spaces:
Sleeping
Sleeping
Update app.py
Browse files1234567811 unmodified lines2021222324252613 unmodified lines40414243444546474849505152import osimport gradio as grfrom openai import OpenAIfrom prompts.main_prompt import MAIN_PROMPT # β Fix Import Pathfrom prompts.initial_prompt import INITIAL_PROMPT # β Ensure Initial Prompt is Included# β Ensure OpenAI API Key is Set (Use Secrets in Hugging Face)OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")11 unmodified linesassistant_reply = client.chat.completions.create(model="gpt-4o",messages=[{"role": "system", "content": MAIN_PROMPT},*[{"role": "user", "content": u} if i % 2 == 0 else {"role": "assistant", "content": a}for i, (u, a) in enumerate(history)13 unmodified lines# β Gradio UIwith gr.Blocks() as demo:gr.Markdown("# **AI-Guided Math PD Chatbot**")chatbot = gr.Chatbot(value=[("", INITIAL_PROMPT)], # β Shows Initial Prompt on Startupheight=500)state_history = gr.State([("", INITIAL_PROMPT)]) # β Ensures History Starts with Initial Promptuser_input = gr.Textbox(placeholder="Type your message here...", label="Your Input")1234567811 unmodified lines2021222324252613 unmodified lines4041424344454647484950515253import osimport gradio as grfrom openai import OpenAIfrom prompts.main_prompt import MAIN_PROMPT # β Import Main Prompt Correctlyfrom prompts.initial_prompt import INITIAL_PROMPT # β Import Initial Prompt# β Ensure OpenAI API Key is Set (Use Secrets in Hugging Face)OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")11 unmodified linesassistant_reply = client.chat.completions.create(model="gpt-4o",messages=[{"role": "system", "content": MAIN_PROMPT}, # β Ensures MAIN_PROMPT is used first*[{"role": "user", "content": u} if i % 2 == 0 else {"role": "assistant", "content": a}for i, (u, a) in enumerate(history)13 unmodified lines# β Gradio UIwith gr.Blocks() as demo:gr.Markdown("# **AI-Guided Math PD Chatbot**")# β Start Chatbot with MAIN_PROMPT Instead of Initial Reflectionchatbot = gr.Chatbot(value=[("", MAIN_PROMPT)], # β Ensures chatbot begins with the math problemsheight=500)state_history = gr.State([("", MAIN_PROMPT)]) # β Makes sure history starts correctlyuser_input = gr.Textbox(placeholder="Type your message here...", label="Your Input")
app.py+7-6