panchajanya1999 commited on
Commit
d9882b0
·
verified ·
1 Parent(s): 72bd9e6

app: Add initial application file

Browse files

Signed-off-by: Panchajanya1999 <[email protected]>

Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ######################################
2
+ ##
3
+ ## ChatBot using OpenAI
4
+ ##
5
+ ######################################
6
+
7
+ import os
8
+ import openai as opai
9
+ import gradio as gr
10
+
11
+ opai.api_key = os.getenv("OPENAI_API_KEY")
12
+
13
+ # make prompt accept command line argument
14
+ # prompt = input("Enter prompt: ")
15
+ # setup a function that accepts propmpt and returns a response using "gpt-3.5-turbo" model
16
+
17
+ def chatbot(prompt, temperature = 0.2):
18
+ response = opai.ChatCompletion.create(
19
+ model = "gpt-3.5-turbo",
20
+ max_tokens = 100,
21
+ temperature = temperature,
22
+ frequency_penalty = 0,
23
+ presence_penalty = 0.6,
24
+ messages = [
25
+ {"role": "user", "content": prompt}
26
+ ]
27
+ )
28
+ return response['choices'][0]['message']['content']
29
+
30
+ # test the function
31
+ demo = gr.Interface(
32
+ fn = chatbot,
33
+ inputs = [gr.Textbox(lines=5, label="Prompt", placeholder="Enter prompt here", info = "Enter a prompt and the chatbot will generate a response."), gr.Slider(0, 1, 0.2, step = 0.1, label="Temperature", info = "The higher the temperature, the more creative the response will be.")],
34
+ outputs = gr.Textbox(label="Response", lines=10),
35
+ title = "ChatGenius - An OpenAI self-tuned chatbot based on GPT-3.5 Turbo",
36
+ description = "Enter a prompt and the chatbot will generate a response.",
37
+ theme=gr.themes.Monochrome()
38
+ )
39
+ demo.launch(share=True)