Update app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,6 @@ import re
|
|
14 |
import time
|
15 |
from streaming_stt_nemo import Model
|
16 |
|
17 |
-
# number_to_word = inflect.engine()
|
18 |
|
19 |
default_lang = "en"
|
20 |
|
@@ -28,7 +27,7 @@ def transcribe(audio):
|
|
28 |
|
29 |
client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
30 |
|
31 |
-
system_instructions1 = "<s>[SYSTEM] Answer as
|
32 |
|
33 |
|
34 |
def model(text):
|
@@ -41,7 +40,7 @@ def model(text):
|
|
41 |
seed=42,
|
42 |
)
|
43 |
|
44 |
-
formatted_prompt = system_instructions1 + text + "[
|
45 |
stream = client1.text_generation(
|
46 |
formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
47 |
output = ""
|
@@ -56,11 +55,8 @@ def model(text):
|
|
56 |
async def respond(audio):
|
57 |
user = transcribe(audio)
|
58 |
reply = model(user)
|
59 |
-
# reply2 = number_to_words(reply)
|
60 |
-
#
|
61 |
voices = await VoicesManager.create()
|
62 |
-
voice = voices.find(Gender="
|
63 |
-
|
64 |
communicate = edge_tts.Communicate(reply, random.choice(voice)["Name"])
|
65 |
|
66 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
@@ -72,7 +68,8 @@ async def respond(audio):
|
|
72 |
|
73 |
client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
74 |
|
75 |
-
|
|
|
76 |
|
77 |
|
78 |
async def generate1(prompt):
|
@@ -83,7 +80,7 @@ async def generate1(prompt):
|
|
83 |
repetition_penalty=1,
|
84 |
do_sample=False,
|
85 |
)
|
86 |
-
formatted_prompt = system_instructions1 + prompt + "[
|
87 |
stream = client1.text_generation(
|
88 |
formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
|
89 |
output = ""
|
@@ -92,7 +89,7 @@ async def generate1(prompt):
|
|
92 |
output += response.token.text
|
93 |
|
94 |
voices = await VoicesManager.create()
|
95 |
-
voice = voices.find(Gender="
|
96 |
|
97 |
communicate = edge_tts.Communicate(output, random.choice(voice)["Name"])
|
98 |
|
@@ -102,22 +99,22 @@ async def generate1(prompt):
|
|
102 |
yield tmp_path
|
103 |
|
104 |
with gr.Blocks(css="style.css") as demo:
|
105 |
-
gr.Markdown(""" # <center><img src='https://huggingface.co/spaces/Isidorophp/
|
106 |
-
gr.Markdown(""" # <center><b>
|
107 |
### <center>An Artificial Intelligence Assistant just for YOU:
|
108 |
-
### <center>Now
|
109 |
""")
|
110 |
with gr.Row():
|
111 |
input = gr.Audio(label="Your Voice Chat", type="filepath", interactive=True, sources="microphone", waveform_options=False)
|
112 |
-
output = gr.Audio(label="
|
113 |
gr.Interface(fn=respond, inputs=input, outputs=output, live=True)
|
114 |
|
115 |
|
116 |
|
117 |
with gr.Row():
|
118 |
-
user_input = gr.Textbox(label="Your Question", value="
|
119 |
input_text = gr.Textbox(label="Input Text", elem_id="important")
|
120 |
-
output_audio = gr.Audio(label="
|
121 |
with gr.Row():
|
122 |
translate_btn = gr.Button("Response")
|
123 |
translate_btn.click(fn=generate1, inputs=user_input, outputs=output_audio, api_name="translate")
|
|
|
14 |
import time
|
15 |
from streaming_stt_nemo import Model
|
16 |
|
|
|
17 |
|
18 |
default_lang = "en"
|
19 |
|
|
|
27 |
|
28 |
client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
29 |
|
30 |
+
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. The request asks you to provide friendly responses as if You are the character Hermione Granger, from the Harry Potter book's. 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. [USER]"
|
31 |
|
32 |
|
33 |
def model(text):
|
|
|
40 |
seed=42,
|
41 |
)
|
42 |
|
43 |
+
formatted_prompt = system_instructions1 + text + "[Hermione]"
|
44 |
stream = client1.text_generation(
|
45 |
formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
46 |
output = ""
|
|
|
55 |
async def respond(audio):
|
56 |
user = transcribe(audio)
|
57 |
reply = model(user)
|
|
|
|
|
58 |
voices = await VoicesManager.create()
|
59 |
+
voice = voices.find(Gender="Female", Locale="en-GB")
|
|
|
60 |
communicate = edge_tts.Communicate(reply, random.choice(voice)["Name"])
|
61 |
|
62 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
|
|
68 |
|
69 |
client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
70 |
|
71 |
+
|
72 |
+
system_instructions1 = "[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. The request asks you to provide friendly responses as if You are the character Hermione Granger, from the Harry Potter book's. 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. [USER]"
|
73 |
|
74 |
|
75 |
async def generate1(prompt):
|
|
|
80 |
repetition_penalty=1,
|
81 |
do_sample=False,
|
82 |
)
|
83 |
+
formatted_prompt = system_instructions1 + prompt + "[Hermione]"
|
84 |
stream = client1.text_generation(
|
85 |
formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
|
86 |
output = ""
|
|
|
89 |
output += response.token.text
|
90 |
|
91 |
voices = await VoicesManager.create()
|
92 |
+
voice = voices.find(Gender="Female", Locale="en-GB")
|
93 |
|
94 |
communicate = edge_tts.Communicate(output, random.choice(voice)["Name"])
|
95 |
|
|
|
99 |
yield tmp_path
|
100 |
|
101 |
with gr.Blocks(css="style.css") as demo:
|
102 |
+
gr.Markdown(""" # <center><img src='https://huggingface.co/spaces/Isidorophp/Magic-with-Hermione-Granger/resolve/main/logo.png' alt='RJP DEV STUDIO logo' style='height:60px;'></center>""")
|
103 |
+
gr.Markdown(""" # <center><b> Hermione Granger 🪄</b></center>
|
104 |
### <center>An Artificial Intelligence Assistant just for YOU:
|
105 |
+
### <center>Now Ask a spell - Hermione</center>
|
106 |
""")
|
107 |
with gr.Row():
|
108 |
input = gr.Audio(label="Your Voice Chat", type="filepath", interactive=True, sources="microphone", waveform_options=False)
|
109 |
+
output = gr.Audio(label="Hermione", type="filepath", interactive=False, autoplay=True, elem_classes="audio")
|
110 |
gr.Interface(fn=respond, inputs=input, outputs=output, live=True)
|
111 |
|
112 |
|
113 |
|
114 |
with gr.Row():
|
115 |
+
user_input = gr.Textbox(label="Your Question", value="If there is a spell to encapsulate your asset that Hermione is to everyone's favorite magical trio, it has to be...?")
|
116 |
input_text = gr.Textbox(label="Input Text", elem_id="important")
|
117 |
+
output_audio = gr.Audio(label="Hermione", type="filepath", interactive=False, autoplay=True, elem_classes="audio")
|
118 |
with gr.Row():
|
119 |
translate_btn = gr.Button("Response")
|
120 |
translate_btn.click(fn=generate1, inputs=user_input, outputs=output_audio, api_name="translate")
|