Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 # β
|
5 |
-
from prompts.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,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=[("",
|
46 |
height=500
|
47 |
)
|
48 |
|
49 |
-
state_history = gr.State([("",
|
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 |
|