Spaces:
Sleeping
Sleeping
Update app.py
Browse files123454567811 unmodified lines202122232324252613 unmodified lines4041424343444545464748494950515253import 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 Includedfrom 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 lines assistant_reply = client.chat.completions.create( model="gpt-4o", messages=[ {"role": "system", "content": MAIN_PROMPT}, {"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 Reflection chatbot = gr.Chatbot( value=[("", INITIAL_PROMPT)], # β
Shows Initial Prompt on Startup value=[("", MAIN_PROMPT)], # β
Ensures chatbot begins with the math problems height=500 )
state_history = gr.State([("", INITIAL_PROMPT)]) # β
Ensures History Starts with Initial Prompt state_history = gr.State([("", MAIN_PROMPT)]) # β
Makes sure history starts correctly
user_input = gr.Textbox(placeholder="Type your message here...", label="Your Input")
app.py+7-6