RamV commited on
Commit
fc7bcef
·
1 Parent(s): c811100

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -40
app.py CHANGED
@@ -2,46 +2,41 @@ import os
2
  import openai
3
  import gradio as gr
4
 
5
- api_key = os.environ.get("OPENAI_API_KEY")
6
-
7
- start_sequence = "\nAI:"
8
- restart_sequence = "\nHuman: "
9
-
10
- # Define the conversation prompt
11
- conversation_prompt = "Welcome to ChatRobo, kindly type in your enquiries: "
12
-
13
- # Define the function to generate a response from the GPT model
14
- def openai_chat_history(input, history):
15
- history = history or []
16
- if input.strip() != "":
17
- s = list(sum(history, ()))
18
- s.append(input)
19
- inp = ' '.join(s)
20
- output = openai_create(inp)
21
- history.append((input, output))
22
- return history[-1][1]
23
  else:
24
- return ""
25
-
26
- def openai_create(prompt):
27
- response = openai.Completion.create(
28
- model="text-davinci-003",
29
- prompt=prompt,
30
- temperature=0.9,
31
- max_tokens=150,
32
- top_p=1,
33
- frequency_penalty=0,
34
- presence_penalty=0.6,
35
- stop=["Human:", "AI:"]
36
- )
37
-
38
- return response.choices[0].text
39
-
40
- block = gr.Interface(
41
- fn=openai_chat_history,
42
- inputs=[gr.inputs.Textbox(placeholder=conversation_prompt)],
43
- outputs=[gr.outputs.Textbox(label="ChatRobo Output")]
44
- )
45
- block.launch()
 
 
 
 
46
 
47
 
 
2
  import openai
3
  import gradio as gr
4
 
5
+ # Set up OpenAI API credentials
6
+ openai.api_key = "YOUR_API_KEY"
7
+
8
+ # Define a function to generate a response to user input
9
+ def generate_response(user_input):
10
+ # Check if user input contains the phrase "who created you"
11
+ if "who created you" in user_input.lower():
12
+ # Generate a response that includes your name
13
+ chat_response = f"I was created by {ramv}!"
 
 
 
 
 
 
 
 
 
14
  else:
15
+ # Construct the prompt with the user input
16
+ prompt = f"You said: {user_input}"
17
+
18
+ # Generate a response using the OpenAI API
19
+ response = openai.Completion.create(
20
+ engine="text-davinci-002",
21
+ prompt=prompt,
22
+ temperature=0.7,
23
+ max_tokens=1024,
24
+ n=1,
25
+ stop=None,
26
+ frequency_penalty=0,
27
+ presence_penalty=0
28
+ )
29
+
30
+ # Extract the response from the API output
31
+ chat_response = response.choices[0].text.strip()
32
+
33
+ return chat_response
34
+
35
+ # Test the chatbot
36
+ while True:
37
+ user_input = input("You: ")
38
+ response = generate_response(user_input)
39
+ print("Chatbot:", response)
40
+
41
 
42