Dagfinn1962 commited on
Commit
6caa426
1 Parent(s): 8fee7a9

Create app2.py

Browse files
Files changed (1) hide show
  1. app2.py +35 -0
app2.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+ import os
4
+
5
+ # Read the API key from the .env file
6
+ openai.api_key = os.getenv("API_KEY")
7
+
8
+ # Define the chatbot function
9
+ def chatbot(message):
10
+ response = openai.Completion.create(
11
+ model="gpt-3.5-turbo",
12
+ prompt=message,
13
+ max_tokens=50,
14
+ temperature=0.8,
15
+ )
16
+ return response.choices[0].text.strip()
17
+
18
+ # Create the interface
19
+ textbox = gr.inputs.Textbox(label="Chat Message")
20
+ button = gr.outputs.Button(label="Submit")
21
+ output_text = gr.outputs.Textbox(label="Chatbot Response")
22
+
23
+ def chat_interface(message):
24
+ response = chatbot(message)
25
+ return response
26
+
27
+ gr.Interface(
28
+ fn=chat_interface,
29
+ inputs=textbox,
30
+ outputs=output_text,
31
+ title="Chat with GPT-3.5 Turbo",
32
+ description="This is a chatbot powered by GPT-3.5 Turbo.",
33
+ theme="huggingface",
34
+ server_port=8080 # Change this to the desired port number
35
+ ).launch()