Spaces:
Sleeping
Sleeping
| import openai | |
| import gradio as gr | |
| from gradio.themes.base import Base | |
| from gradio.themes.utils import colors, fonts, sizes | |
| import os | |
| openai.api_key = os.environ.get("openai.api_key") | |
| messages = [ | |
| {"role": "system", "content": "You are a math teacher. Help with solution and explaination of the math problem that is asked. If it is not related to Math or you do not know the answer, say Sorry I am not sure of that one."}, | |
| ] | |
| def chatbot(input): | |
| if input: | |
| messages.append({"role": "assistant", "content": input}) | |
| chat = openai.ChatCompletion.create( | |
| model="gpt-3.5-turbo", messages=messages | |
| ) | |
| reply = chat.choices[0].message.content | |
| messages.append({"role": "user", "content": reply}) | |
| return reply | |
| inputs = gr.components.Textbox(lines=7,label="Type your question in the box below.") | |
| outputs = gr.components.Textbox(lines=7, label="Reply") | |
| gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, text_color="red",title="Solve Your Math Problems!", | |
| theme="soft").launch(share=False) | |