Spaces:
Sleeping
Sleeping
Commit
·
a2ea3bb
1
Parent(s):
2b70c4a
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,38 @@
|
|
| 1 |
import openai
|
| 2 |
import os
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|