zlmqi commited on
Commit
47d89c5
1 Parent(s): d0086da

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+ import os
4
+
5
+ openai.api_key = os.getenv("OPENAI_API_KEY")
6
+
7
+ messages = [
8
+ {"role": "system", "content": "You are a learning assistant specialized in business information systems."},
9
+ ]
10
+
11
+ def chatbot(input):
12
+ if input:
13
+ messages.append({"role": "user", "content": input})
14
+ chat = openai.chat.completions.create(
15
+ model="gpt-3.5-turbo", messages=messages
16
+ )
17
+ reply = chat.choices[0].message.content
18
+ messages.append({"role": "assistant", "content": reply})
19
+ return reply
20
+
21
+ inputs = gr.inputs.Textbox(lines=7, label="Ask questions related to the course.")
22
+ outputs = gr.outputs.Textbox(label="Reply")
23
+
24
+ iface = gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="Virtual TA",
25
+ description="This is a prototype of learning assistant designed for MIS 320 online section.",
26
+ theme="compact")
27
+
28
+ iface.launch(inline=True)