alibicer commited on
Commit
0adaba1
·
verified ·
1 Parent(s): 920cdf0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -13
app.py CHANGED
@@ -1,21 +1,27 @@
1
  import os
2
  import gradio as gr
3
- from dotenv import load_dotenv
4
  from openai import OpenAI
5
- from prompts.main_prompt import MAIN_PROMPT
6
-
7
- # ✅ Load API key
8
- if os.path.exists(".env"):
9
- load_dotenv(".env")
10
 
 
11
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
12
 
13
- # ✅ Ensure OpenAI API Key Exists
14
  if not OPENAI_API_KEY:
15
- raise ValueError("Missing OpenAI API Key! Make sure .env file contains OPENAI_API_KEY.")
16
 
17
  client = OpenAI(api_key=OPENAI_API_KEY)
18
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  def respond(user_message, history):
20
  if not user_message:
21
  return "", history
@@ -35,16 +41,16 @@ def respond(user_message, history):
35
  temperature=0.7,
36
  ).choices[0].message.content
37
  except Exception as e:
38
- assistant_reply = f"Error: {str(e)}"
39
 
40
  history.append((user_message, assistant_reply))
41
 
42
  return "", history
43
 
44
- # ✅ Ensure Gradio UI Loads
45
  with gr.Blocks() as demo:
46
- gr.Markdown("# AI-Guided Math PD Chatbot")
47
-
48
  chatbot = gr.Chatbot(height=500)
49
  state_history = gr.State([("", MAIN_PROMPT)])
50
 
@@ -61,4 +67,4 @@ with gr.Blocks() as demo:
61
  )
62
 
63
  if __name__ == "__main__":
64
- demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
 
1
  import os
2
  import gradio as gr
 
3
  from openai import OpenAI
 
 
 
 
 
4
 
5
+ # ✅ Ensure OpenAI API Key is Set (Use Secrets in Hugging Face)
6
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
7
 
 
8
  if not OPENAI_API_KEY:
9
+ raise ValueError("⚠️ Missing OpenAI API Key! Set it in Hugging Face 'Settings' → 'Secrets'.")
10
 
11
  client = OpenAI(api_key=OPENAI_API_KEY)
12
 
13
+ MAIN_PROMPT = """
14
+ ### **Module 3: Proportional Reasoning Problem Types**
15
+ #### **Task Introduction**
16
+ "Welcome to this module on proportional reasoning problem types!
17
+ Your task is to explore three different problem types foundational to proportional reasoning:
18
+ 1️⃣ **Missing Value Problems**
19
+ 2️⃣ **Numerical Comparison Problems**
20
+ 3️⃣ **Qualitative Reasoning Problems**
21
+ You will solve and compare these problems, **identify their characteristics**, and finally **create your own problems** for each type.
22
+ 🚀 **Let's begin! Solve each problem and analyze your solution process.**"
23
+ """
24
+
25
  def respond(user_message, history):
26
  if not user_message:
27
  return "", history
 
41
  temperature=0.7,
42
  ).choices[0].message.content
43
  except Exception as e:
44
+ assistant_reply = f"⚠️ Error: {str(e)}"
45
 
46
  history.append((user_message, assistant_reply))
47
 
48
  return "", history
49
 
50
+ # ✅ Gradio UI
51
  with gr.Blocks() as demo:
52
+ gr.Markdown("# **AI-Guided Math PD Chatbot**")
53
+
54
  chatbot = gr.Chatbot(height=500)
55
  state_history = gr.State([("", MAIN_PROMPT)])
56
 
 
67
  )
68
 
69
  if __name__ == "__main__":
70
+ demo.launch()