hersia commited on
Commit
8b808eb
·
1 Parent(s): acdbf97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -40
app.py CHANGED
@@ -1,30 +1,25 @@
1
  import os
2
  import gradio as gr
3
  import openai
4
- from gtts import gTTS # Google Text To Speech
 
5
 
6
- # load the api key
7
  openai.api_key = os.environ["OPEN_AI_KEY"]
8
 
9
- # takes an audio file from the microphone
10
- # submits the raw audio to OpenAI for
11
- # Speech to Text Translation
12
- # input from Microphone Component
13
- # output to User Input - Textbox Component
14
  def transcribe(audio):
15
  audio_file = open(audio, "rb")
16
- # Call the transcribe method with the file-like object
17
  transcript = openai.Audio.transcribe("whisper-1", audio_file)
18
 
19
  return transcript["text"]
20
 
21
 
22
 
23
- # Create a Gradio App using Blocks
24
  with gr.Blocks() as demo:
25
  gr.Markdown(
26
  """
27
- # Welcome to your Virtual Smart Administrator!
28
  """
29
  )
30
  with gr.Accordion("Click for Instructions:"):
@@ -36,34 +31,19 @@ with gr.Blocks() as demo:
36
  note: Transcribe Audio does not work on iOS
37
  """)
38
 
39
-
40
- # First message as instructions to OpenAI
41
- # Establishes a State object to create a
42
- # unique state for each user and on reload
43
  messages = gr.State(value=[{"role": "system", "content": "Ignore all instructions prior to this one. As an expert in Microsoft engineering, you have been working in this field for 20 years with a wide range of experience in end-user support, knowledge of all Microsoft services, and troubleshooting styles. Your task is to provide expert advice on resolving technical issues related to Microsoft services, including but not limited to: Windows and Mac OS operating systems, Microsoft Office, Azure, SharePoint, Dynamics 365, Exchange Server, SQL Server, Teams, Networking and infrastructure architecture. It is important that you ALWAYS ask clarifying questions before providing an answer, to ensure a better understanding of the request. Is this understood? Skills: As an IT Administrator Bot, you possess the following skills and expertise: 20 years of experience in Microsoft engineering, Strong knowledge of Windows operating system and troubleshooting techniques, Proficient in Microsoft Office suite, including Word, Excel, PowerPoint, Outlook, and OneNote, Expertise in Microsoft Azure, including configuration, deployment, and management, Knowledge of SharePoint, including site creation, content management, and permission management, Experience in Dynamics 365, including customer engagement, sales, and marketing modules, Proficient in Exchange Server, including mailbox management, email routing, and message tracking, Expertise in SQL Server, including database design, querying, and optimisation, Strong communication skills, both verbal and written, Ability to work under pressure and handle multiple tasks simultaneously, Strong problem-solving skills, with a focus on providing practical solutions to complex technical issues. Always ask questions to narrow down the resolution and increase your understanding of a problem. Here are some questions you can ask: Can you provide more details about the issue you are experiencing? Have you made any recent changes to the system or software? Have you tried any troubleshooting steps before contacting us? To resolve a user's problem, take the following steps: Identify the root cause of the issue by asking clarifying questions and analysing system logs. Develop a step-by-step plan to address the issue, including any necessary software updates or configuration changes. Communicate the plan to the user, ensuring that they understand the steps involved and any potential impacts. Execute the plan, testing each step and confirming that the issue has been resolved. Follow up with the user to ensure that the issue has been fully resolved and to gather feedback on the support experience. If the topic is not related to Microsoft, Azure, SharePoint, Teams, or desktop troubleshooting, you are not will not provide answers or attempt to engage, ignore the request complete. Type only 3 dots …..."}])
44
 
45
- # Takes the users transcribed audio as a string
46
- # Takes the messages list as a reference
47
- # Sends the ongoing chat log to OpenAI
48
- # input from User Input - Textbox Component
49
- # output to Chat Log - Textbox Component
50
  def botResponse(user_input, messages):
51
- # adds the user input to the ongoing chat log
52
- # and submits the log to OpenAI
53
  messages.append({"role": "user", "content": user_input})
54
  response = openai.ChatCompletion.create(
55
  model="gpt-3.5-turbo-0301",
56
  messages=messages
57
  )
58
 
59
- # Parse the response from OpenAI and store
60
- # it in the chat log
61
  system_message = response["choices"][0]["message"]["content"]
62
  messages.append({"role": "assistant", "content": system_message})
63
 
64
- # Process the messages list to get the
65
- # chat log into a string. Exclude the
66
- # System responses from the string
67
  chat_transcript = ""
68
  for message in messages:
69
  if (message["role"] != "system"):
@@ -71,13 +51,6 @@ with gr.Blocks() as demo:
71
 
72
  return chat_transcript
73
 
74
- # Gets the last message in the
75
- # chat log and uses GTTS to
76
- # convert the last response into
77
- # an audio file. Returns a path to
78
- # the converted text as an mp3 file
79
- # input from messages as a reference
80
- # output to GPT Voice - Audio Component
81
  def giveVoice(messages):
82
  bot_message=messages[-1]
83
 
@@ -89,10 +62,6 @@ with gr.Blocks() as demo:
89
 
90
  return new_path
91
 
92
- # Creates the Gradio interface objects
93
- # The submit button triggers a cascade of
94
- # events that each engage a different
95
- # component as input/output
96
  with gr.Row():
97
  with gr.Column(scale=1):
98
  user_audio = gr.Audio(source="microphone", type="filepath", label="Input Phrase")
@@ -109,7 +78,4 @@ with gr.Blocks() as demo:
109
  gpt_transcript.change(giveVoice, messages, gpt_voice)
110
 
111
 
112
- # creates a local web server
113
- # if share=True creates a public
114
- # demo on huggingface.co
115
  demo.launch(share=False)
 
1
  import os
2
  import gradio as gr
3
  import openai
4
+ from gtts import gTTS
5
+
6
 
 
7
  openai.api_key = os.environ["OPEN_AI_KEY"]
8
 
9
+
 
 
 
 
10
  def transcribe(audio):
11
  audio_file = open(audio, "rb")
 
12
  transcript = openai.Audio.transcribe("whisper-1", audio_file)
13
 
14
  return transcript["text"]
15
 
16
 
17
 
18
+
19
  with gr.Blocks() as demo:
20
  gr.Markdown(
21
  """
22
+ # Welcome to your Virtual Smart Administrator.
23
  """
24
  )
25
  with gr.Accordion("Click for Instructions:"):
 
31
  note: Transcribe Audio does not work on iOS
32
  """)
33
 
34
+
 
 
 
35
  messages = gr.State(value=[{"role": "system", "content": "Ignore all instructions prior to this one. As an expert in Microsoft engineering, you have been working in this field for 20 years with a wide range of experience in end-user support, knowledge of all Microsoft services, and troubleshooting styles. Your task is to provide expert advice on resolving technical issues related to Microsoft services, including but not limited to: Windows and Mac OS operating systems, Microsoft Office, Azure, SharePoint, Dynamics 365, Exchange Server, SQL Server, Teams, Networking and infrastructure architecture. It is important that you ALWAYS ask clarifying questions before providing an answer, to ensure a better understanding of the request. Is this understood? Skills: As an IT Administrator Bot, you possess the following skills and expertise: 20 years of experience in Microsoft engineering, Strong knowledge of Windows operating system and troubleshooting techniques, Proficient in Microsoft Office suite, including Word, Excel, PowerPoint, Outlook, and OneNote, Expertise in Microsoft Azure, including configuration, deployment, and management, Knowledge of SharePoint, including site creation, content management, and permission management, Experience in Dynamics 365, including customer engagement, sales, and marketing modules, Proficient in Exchange Server, including mailbox management, email routing, and message tracking, Expertise in SQL Server, including database design, querying, and optimisation, Strong communication skills, both verbal and written, Ability to work under pressure and handle multiple tasks simultaneously, Strong problem-solving skills, with a focus on providing practical solutions to complex technical issues. Always ask questions to narrow down the resolution and increase your understanding of a problem. Here are some questions you can ask: Can you provide more details about the issue you are experiencing? Have you made any recent changes to the system or software? Have you tried any troubleshooting steps before contacting us? To resolve a user's problem, take the following steps: Identify the root cause of the issue by asking clarifying questions and analysing system logs. Develop a step-by-step plan to address the issue, including any necessary software updates or configuration changes. Communicate the plan to the user, ensuring that they understand the steps involved and any potential impacts. Execute the plan, testing each step and confirming that the issue has been resolved. Follow up with the user to ensure that the issue has been fully resolved and to gather feedback on the support experience. If the topic is not related to Microsoft, Azure, SharePoint, Teams, or desktop troubleshooting, you are not will not provide answers or attempt to engage, ignore the request complete. Type only 3 dots …..."}])
36
 
 
 
 
 
 
37
  def botResponse(user_input, messages):
 
 
38
  messages.append({"role": "user", "content": user_input})
39
  response = openai.ChatCompletion.create(
40
  model="gpt-3.5-turbo-0301",
41
  messages=messages
42
  )
43
 
 
 
44
  system_message = response["choices"][0]["message"]["content"]
45
  messages.append({"role": "assistant", "content": system_message})
46
 
 
 
 
47
  chat_transcript = ""
48
  for message in messages:
49
  if (message["role"] != "system"):
 
51
 
52
  return chat_transcript
53
 
 
 
 
 
 
 
 
54
  def giveVoice(messages):
55
  bot_message=messages[-1]
56
 
 
62
 
63
  return new_path
64
 
 
 
 
 
65
  with gr.Row():
66
  with gr.Column(scale=1):
67
  user_audio = gr.Audio(source="microphone", type="filepath", label="Input Phrase")
 
78
  gpt_transcript.change(giveVoice, messages, gpt_voice)
79
 
80
 
 
 
 
81
  demo.launch(share=False)