Spaces:
Sleeping
Sleeping
Commit
·
2bdde4b
1
Parent(s):
91df1b6
Update app.py
Browse filescomplete rework
app.py
CHANGED
|
@@ -1,32 +1,47 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
response = openai.Completion.create(
|
| 17 |
-
engine=
|
| 18 |
prompt=prompt,
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
)
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import gradio as gr
|
| 3 |
|
| 4 |
+
# Set up OpenAI API credentials
|
| 5 |
+
openai.api_key = OPENAPI_KEY
|
| 6 |
+
|
| 7 |
+
# Set up the GPT-3 model
|
| 8 |
+
model_engine = "gpt-3.5-turbo-0301"
|
| 9 |
+
prompt = (
|
| 10 |
+
"I want you to act as a math teacher. I will provide some mathematical equations or concepts, "
|
| 11 |
+
"and it will be your job to explain them in easy-to-understand terms. This could include providing "
|
| 12 |
+
"step-by-step instructions for solving a problem, demonstrating various techniques with visuals or "
|
| 13 |
+
"suggesting online resources for further study. My first request is \"I need help understanding how "
|
| 14 |
+
"probability works.\""
|
| 15 |
+
)
|
| 16 |
+
temperature = 0.7
|
| 17 |
+
max_tokens = 1000
|
| 18 |
+
context_length = 2
|
| 19 |
+
|
| 20 |
+
# Define the function that generates the response
|
| 21 |
+
def generate_response(prompt):
|
| 22 |
response = openai.Completion.create(
|
| 23 |
+
engine=model_engine,
|
| 24 |
prompt=prompt,
|
| 25 |
+
temperature=temperature,
|
| 26 |
+
max_tokens=max_tokens,
|
| 27 |
+
n = 1,
|
| 28 |
+
stop=None,
|
| 29 |
+
frequency_penalty=0,
|
| 30 |
+
presence_penalty=0,
|
| 31 |
+
context=context_length * [prompt],
|
| 32 |
)
|
| 33 |
+
|
| 34 |
+
return response.choices[0].text.strip()
|
| 35 |
+
|
| 36 |
+
# Set up the Gradio interface
|
| 37 |
+
io = gr.Interface(
|
| 38 |
+
generate_response,
|
| 39 |
+
"textbox",
|
| 40 |
+
"textbox",
|
| 41 |
+
title="Chat with a Math Teacher",
|
| 42 |
+
description="Type a math question or concept that you need help understanding, and the math teacher will explain it to you in easy-to-understand terms!",
|
| 43 |
+
article="This app uses the GPT-3 language model to generate responses. The math teacher is programmed to provide step-by-step instructions for solving a problem, demonstrate various techniques with visuals, or suggest online resources for further study. Please keep in mind that this is an AI language model and may not always provide accurate or complete information.",
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
# Launch the interface
|
| 47 |
+
io.launch()
|