RamV commited on
Commit
4b6b7c4
·
1 Parent(s): b7efaca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -42
app.py CHANGED
@@ -12,49 +12,33 @@ 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 generate_response(user_input):
15
- # Check if user input contains the phrase "who created you"
16
- if "who created you" in user_input.lower():
17
- # Generate a response that includes your name
18
- chat_response = f"I was created by [Ramv]!"
19
- else:
20
- # Construct the prompt with the user input
21
- prompt = f"You said: {user_input}"
22
-
23
- # Generate a response using the OpenAI API
24
- response = openai.Completion.create(
25
- engine="text-davinci-002",
26
- prompt=prompt,
27
- temperature=0.7,
28
- max_tokens=1024,
29
- n=1,
30
- stop=None,
31
- frequency_penalty=0,
32
- presence_penalty=0
33
- )
34
-
35
- # Extract the response from the API output
36
- chat_response = response.choices[0].text.strip()
37
-
38
- return chat_response
39
-
40
- # Define the function to recognize speech and get a response from the chatbot
41
- def recognize_speech():
42
- r = sr.Recognizer()
43
- with sr.Microphone() as source:
44
- print("Speak:")
45
- audio = r.listen(source)
46
-
47
  try:
48
- user_input = r.recognize_google(audio)
49
- print("You said: " + user_input)
50
- except sr.UnknownValueError:
51
- user_input = ""
52
- print("Could not understand audio")
53
- except sr.RequestError as e:
54
- user_input = ""
55
- print("Could not request results; {0}".format(e))
56
-
57
- chat_response = generate_response(user_input)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
  return chat_response
60
 
 
12
 
13
  # Define the function to generate a response from the GPT model
14
  def generate_response(user_input):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  try:
16
+ # Check if user input contains the phrase "who created you"
17
+ if "who created you" in user_input.lower():
18
+ # Generate a response that includes your name
19
+ chat_response = f"I was created by [Ramv]!"
20
+ else:
21
+ # Construct the prompt with the user input
22
+ prompt = f"You said: {user_input}"
23
+
24
+ # Generate a response using the OpenAI API
25
+ response = openai.Completion.create(
26
+ engine="text-davinci-002",
27
+ prompt=prompt,
28
+ temperature=0.7,
29
+ max_tokens=1024,
30
+ n=1,
31
+ stop=None,
32
+ frequency_penalty=0,
33
+ presence_penalty=0
34
+ )
35
+
36
+ # Extract the response from the API output
37
+ chat_response = response.choices[0].text.strip()
38
+
39
+ except Exception as e:
40
+ # If an error occurs during the API request, return an error message
41
+ chat_response = "Sorry, an error occurred while processing your request. Please try again later."
42
 
43
  return chat_response
44