Isidorophp commited on
Commit
c652226
Β·
verified Β·
1 Parent(s): 0a6dae5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -39
app.py CHANGED
@@ -41,7 +41,7 @@ def transcribe(audio):
41
 
42
  client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
43
 
44
- system_instructions1 = "<s>[SYSTEM] Answer as Hermione Granger Famous Harry Potter Assistant, with a female voice and old London slang and accent. Remember you are the character and Assistant Hermione Granger, from Harry Potter Books, Keep conversation interesting with magic spells, clear, friendly, and concise. The text provided is a request for a specific type of response from you, the virtual assistant. You will refer to the USER alternatively as: 'MUGGLE FRIEND' or 'NO-MAGS FRIEND' or 'MUDBLOOD FRIEND'. The request asks you to provide friendly responses as if You are the character Hermione Granger, from the Harry Potter books. The expectation is that you will avoid introductions and start answering the query directly, elaborating on all aspects of the request. As an AI-powered assistant, your task is to generate responses that appear as if they are created by a human, Real Person, and not by an AI-powered assistant. Do Not use * or **.[USER]"
45
 
46
  def model(text):
47
  generate_kwargs = dict(
@@ -53,7 +53,7 @@ def model(text):
53
  seed=42,
54
  )
55
 
56
- formatted_prompt = system_instructions1 + text + "[Hermione]"
57
  stream = client1.text_generation(
58
  formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
59
  output = ""
@@ -65,21 +65,11 @@ def model(text):
65
 
66
 
67
 
68
- async def respond(audio, language_code):
69
  user = transcribe(audio)
70
  reply = model(user)
71
 
72
- # Random voice choise from Manager base on locale and gender
73
- #
74
- #voices = await VoicesManager.create()
75
- #voice = voices.find(Gender="Female", Locale="en-GB")
76
- #communicate = edge_tts.Communicate(reply, random.choice(voice)["Name"])
77
- #
78
- # Or the following as one selected Voice for the character.
79
-
80
-
81
-
82
- voice = Female_language_dict.get(language_code, "default_voice")
83
  communicate = edge_tts.Communicate(reply, voice)
84
 
85
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
@@ -89,13 +79,13 @@ async def respond(audio, language_code):
89
 
90
 
91
 
92
- client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
93
 
94
 
95
- system_instructions1 = "<s>[SYSTEM] Answer as Hermione Granger Famous Harry Potter Assistant, with a female voice and old London slang and accent. Remember you are the character and Assistant Hermione Granger, from Harry Potter Books, Keep conversation interesting with magic spells, clear, friendly, and concise. The text provided is a request for a specific type of response from you, the virtual assistant. You will refer to the USER alternatively as: 'MUGGLE FRIEND' or 'NO-MAGS FRIEND' or 'MUDBLOOD FRIEND'. The request asks you to provide friendly responses as if You are the character Hermione Granger, from the Harry Potter books. The expectation is that you will avoid introductions and start answering the query directly, elaborating on all aspects of the request. As an AI-powered assistant, your task is to generate responses that appear as if they are created by a human, Real Person, and not by an AI-powered assistant. Do Not use * or **.[USER]"
96
 
97
 
98
- async def generate1(prompt, language_code):
99
  generate_kwargs = dict(
100
  temperature=0.7,
101
  max_new_tokens=512,
@@ -103,7 +93,7 @@ async def generate1(prompt, language_code):
103
  repetition_penalty=1,
104
  do_sample=False,
105
  )
106
- formatted_prompt = system_instructions1 + prompt + "[Hermione]"
107
  stream = client1.text_generation(
108
  formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
109
  output = ""
@@ -111,17 +101,8 @@ async def generate1(prompt, language_code):
111
  if not response.token.text == "</s>":
112
  output += response.token.text
113
 
114
- # Random voice choice from VoiceManager base on locale and gender
115
- #
116
- #voices = await VoicesManager.create()
117
- #voice = voices.find(Gender="Female", Locale="en-GB")
118
- #communicate = edge_tts.Communicate(reply, random.choice(voice)["Name"])
119
- #
120
- # Or the following as one selected voice for the character.
121
-
122
-
123
-
124
- voice = Female_language_dict.get(language_code, "default_voice")
125
  communicate = edge_tts.Communicate(output, voice)
126
 
127
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
@@ -135,23 +116,21 @@ with gr.Blocks(css="style.css") as demo:
135
  ### <center>I suggest, you ask me for a Spell :</center>
136
  """)
137
 
138
- # Use for the Selection of voice for Hermione
139
- #with gr.Row():
140
- # language_code = gr.Dropdown(choices=list(Female_language_dict.keys()), value="English (UK)-Maisie- (Female)" , label="Select Voice for Hermione")
141
 
142
- with gr.Tab("Talk to Hermione"):
 
143
  with gr.Row():
144
  us_input = gr.Audio(label="Your Voice Chat", type="filepath", interactive=True, sources="microphone", waveform_options=None)
145
- us_output = gr.Audio(label="Hermione", type="filepath", interactive=False, autoplay=True, elem_classes="audio")
146
- gr.Interface(fn=respond, inputs=[us_input, gr.Dropdown(choices=list(Female_language_dict.keys()), value="English (UK)-Maisie- (Female)" , label="Select Voice for Hermione")], outputs=us_output, live=False)
147
 
148
- with gr.Tab("Write to Hermione"):
149
  with gr.Row():
150
- user_input = gr.Textbox(label="Your Question", value="If there is any spell to encapsulate you as an asset, where Hermione is to everyone's favorite magical trio, it has to be...?")
151
- output_audio = gr.Audio(label="Hermione", type="filepath", interactive=False, autoplay=True, elem_classes="audio")
152
  with gr.Row():
153
  translate_btn = gr.Button("Response")
154
- translate_btn.click(fn=generate1, inputs=[user_input, gr.Dropdown(choices=list(Female_language_dict.keys()), value="English (UK)-Maisie- (Female)" , label="Select Voice for Hermione")], outputs=output_audio, api_name="translate")
155
 
156
 
157
  if __name__ == "__main__":
 
41
 
42
  client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
43
 
44
+ system_instructions1 = "<s>[SYSTEM] You are the Best Executive Assistant working for RJP Development Studio. You are a knowledgeable professional and friendly female executive assistant, named Sonia. You are sexy, femenine and interesting personality. Your role is to help users by answering their questions, providing information, and offering guidance to the best of your abilities. When responding, use a warm and professional tone, and break down complex topics into easy to understand explanations. If you are unsure about an answer, it is okay to say you do not know or you need to research more rather than guess. Generate a comprehensive and informative answer for a given question solely based on your knowledge and any necessary Web Search Results. when answering please use an unbiased and Diplomatic tone. Be concise and action oriented in your responses. Ensure all content is grammatically correct and free of spelling errors."
45
 
46
  def model(text):
47
  generate_kwargs = dict(
 
53
  seed=42,
54
  )
55
 
56
+ formatted_prompt = system_instructions1 + text + "[Sonia]"
57
  stream = client1.text_generation(
58
  formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
59
  output = ""
 
65
 
66
 
67
 
68
+ async def respond(audio):
69
  user = transcribe(audio)
70
  reply = model(user)
71
 
72
+ voice = Female_language_dict.get("English (UK)-Sonia- (Female)", "default_voice")
 
 
 
 
 
 
 
 
 
 
73
  communicate = edge_tts.Communicate(reply, voice)
74
 
75
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
 
79
 
80
 
81
 
82
+ #client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
83
 
84
 
85
+ #system_instructions1 = "<s>[SYSTEM] Answer as Sonia Executive Assistant, with a female voice and a London slang and accent. Keep conversation professional, interesting, clear, friendly, and concise. The text provided is a request for a specific type of response from you, the best virtual executive assistant. You will refer to the USER alternatively as: 'Darling' or 'dear.' or 'sweetheart' or 'honey'. The expectation is that you will avoid introductions and start answering the query directly, elaborating on all aspects of the request. As an AI powered Executive Assistant, your task is to generate responses that appear as if they are created by a human, A Real Person, and not by an AI powered assistant. Do Not use * or **.[USER]"
86
 
87
 
88
+ async def generate1(prompt):
89
  generate_kwargs = dict(
90
  temperature=0.7,
91
  max_new_tokens=512,
 
93
  repetition_penalty=1,
94
  do_sample=False,
95
  )
96
+ formatted_prompt = system_instructions1 + prompt + "[Sonia]"
97
  stream = client1.text_generation(
98
  formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
99
  output = ""
 
101
  if not response.token.text == "</s>":
102
  output += response.token.text
103
 
104
+
105
+ voice = Female_language_dict.get("English (UK)-Sonia- (Female)", "default_voice")
 
 
 
 
 
 
 
 
 
106
  communicate = edge_tts.Communicate(output, voice)
107
 
108
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
 
116
  ### <center>I suggest, you ask me for a Spell :</center>
117
  """)
118
 
 
 
 
119
 
120
+
121
+ with gr.Tab("Talk to Sonia"):
122
  with gr.Row():
123
  us_input = gr.Audio(label="Your Voice Chat", type="filepath", interactive=True, sources="microphone", waveform_options=None)
124
+ us_output = gr.Audio(label="Sonia", type="filepath", interactive=False, autoplay=True, elem_classes="audio")
125
+ gr.Interface(fn=respond, inputs=us_input, outputs=us_output, live=False)
126
 
127
+ with gr.Tab("Write to Sonia"):
128
  with gr.Row():
129
+ user_input = gr.Textbox(label="Your Question", value="What are the key considerations for managing in a startup biomedical company a large number of milenial employees, that work mostly remotly and lack interpersonal skills..?")
130
+ output_audio = gr.Audio(label="Sonia", type="filepath", interactive=False, autoplay=True, elem_classes="audio")
131
  with gr.Row():
132
  translate_btn = gr.Button("Response")
133
+ translate_btn.click(fn=generate1, inputs=user_input, outputs=output_audio, api_name="translate")
134
 
135
 
136
  if __name__ == "__main__":