alibicer commited on
Commit
aff9c1d
Β·
verified Β·
1 Parent(s): 3a5f3cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -1,8 +1,8 @@
1
  import os
2
  import gradio as gr
3
  from openai import OpenAI
4
- from prompts.main_prompt import MAIN_PROMPT # βœ… Fix Import Path
5
- from prompts.initial_prompt import INITIAL_PROMPT # βœ… Ensure Initial Prompt is Included
6
 
7
  # βœ… Ensure OpenAI API Key is Set (Use Secrets in Hugging Face)
8
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
@@ -20,7 +20,7 @@ def respond(user_message, history):
20
  assistant_reply = client.chat.completions.create(
21
  model="gpt-4o",
22
  messages=[
23
- {"role": "system", "content": MAIN_PROMPT},
24
  *[
25
  {"role": "user", "content": u} if i % 2 == 0 else {"role": "assistant", "content": a}
26
  for i, (u, a) in enumerate(history)
@@ -40,13 +40,14 @@ def respond(user_message, history):
40
  # βœ… Gradio UI
41
  with gr.Blocks() as demo:
42
  gr.Markdown("# **AI-Guided Math PD Chatbot**")
43
-
 
44
  chatbot = gr.Chatbot(
45
- value=[("", INITIAL_PROMPT)], # βœ… Shows Initial Prompt on Startup
46
  height=500
47
  )
48
 
49
- state_history = gr.State([("", INITIAL_PROMPT)]) # βœ… Ensures History Starts with Initial Prompt
50
 
51
  user_input = gr.Textbox(placeholder="Type your message here...", label="Your Input")
52
 
 
1
  import os
2
  import gradio as gr
3
  from openai import OpenAI
4
+ from prompts.main_prompt import MAIN_PROMPT # βœ… Import Main Prompt Correctly
5
+ from prompts.initial_prompt import INITIAL_PROMPT # βœ… Import Initial Prompt
6
 
7
  # βœ… Ensure OpenAI API Key is Set (Use Secrets in Hugging Face)
8
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
 
20
  assistant_reply = client.chat.completions.create(
21
  model="gpt-4o",
22
  messages=[
23
+ {"role": "system", "content": MAIN_PROMPT}, # βœ… Ensures MAIN_PROMPT is used first
24
  *[
25
  {"role": "user", "content": u} if i % 2 == 0 else {"role": "assistant", "content": a}
26
  for i, (u, a) in enumerate(history)
 
40
  # βœ… Gradio UI
41
  with gr.Blocks() as demo:
42
  gr.Markdown("# **AI-Guided Math PD Chatbot**")
43
+
44
+ # βœ… Start Chatbot with MAIN_PROMPT Instead of Initial Reflection
45
  chatbot = gr.Chatbot(
46
+ value=[("", MAIN_PROMPT)], # βœ… Ensures chatbot begins with the math problems
47
  height=500
48
  )
49
 
50
+ state_history = gr.State([("", MAIN_PROMPT)]) # βœ… Makes sure history starts correctly
51
 
52
  user_input = gr.Textbox(placeholder="Type your message here...", label="Your Input")
53