NeuralJunkie commited on
Commit
a2ea3bb
·
1 Parent(s): 2b70c4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -31
app.py CHANGED
@@ -1,33 +1,38 @@
1
  import openai
2
  import os
3
-
4
- openai.api_key = os.environ["API_KEY"]
5
-
6
- prompt_templates = {"Math Teacher": "I want you to act as a math teacher. I will provide some mathematical equations or concepts, and it will be your job to explain them in easy-to-understand terms. This could include providing step-by-step instructions for solving a problem, demonstrating various techniques with visuals or suggesting online resources for further study. My first request is 'I need help understanding how probability works.'"}
7
-
8
- def submit_message(prompt):
9
- prompt_template = prompt_templates["Math Teacher"]
10
-
11
- system_prompt = ""
12
- if prompt_template:
13
- system_prompt = prompt_template + "\n"
14
-
15
- prompt_msg = prompt + "\n"
16
-
17
- try:
18
- completion = openai.Completion.create(
19
- engine="text-davinci-002",
20
- prompt=system_prompt + prompt_msg,
21
- max_tokens=1024,
22
- n=1,
23
- stop=None,
24
- temperature=0.7,
25
- )
26
-
27
- response = completion.choices[0].text
28
- except Exception as e:
29
- response = f"Sorry, an error occurred: {e}"
30
-
31
- return response
32
-
33
- print(submit_message("I need help understanding how probability works."))
 
 
 
 
 
 
1
  import openai
2
  import os
3
+ import gradio as gr
4
+
5
+ # Fetching API key from environment variable
6
+ API_KEY = os.environ['API_KEY']
7
+
8
+ # Setting up OpenAI API credentials
9
+ openai.api_key = API_KEY
10
+ model_engine = 'text-davinci-002'
11
+ prompt = 'Please solve the following math problem: '
12
+
13
+ # Defining the function to solve math problems
14
+ def math_tutor(problem):
15
+ response = openai.Completion.create(
16
+ engine='gpt-3.5-turbo-0301',
17
+ prompt=prompt + problem,
18
+ max_tokens=50,
19
+ n=1,
20
+ stop=None,
21
+ temperature=0.7,
22
+ )
23
+ answer = response.choices[0].text.strip()
24
+ return answer
25
+
26
+ # Creating a Gradio interface for the math tutor
27
+ iface = gr.Interface(
28
+ fn=math_tutor,
29
+ inputs=gr.inputs.Textbox(label="Enter a math problem"),
30
+ outputs="text",
31
+ title="Math Tutor",
32
+ description="Enter a math problem and the Math Tutor will solve it for you!",
33
+ theme="compact"
34
+ )
35
+
36
+ # Running the Gradio interface
37
+ if __name__ == '__main__':
38
+ iface.launch()