File size: 1,066 Bytes
f1ff2be
 
 
 
 
 
 
 
 
 
cafefba
f1ff2be
 
 
 
 
 
 
 
 
 
 
cafefba
f1ff2be
 
cafefba
 
1
2
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

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)