Isidorophp commited on
Commit
4f592bc
Β·
verified Β·
1 Parent(s): 8cde3ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -69
app.py CHANGED
@@ -29,78 +29,10 @@ Female_language_dict = {
29
 
30
  default_lang = "en"
31
  engines = { default_lang: Model(default_lang) }
 
32
  client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
33
  system_instructions1 = "<s>[SYSTEM] Hello, I am Sonia, your professional and knowledgeable Executive Assistant at RJP Development Studio. I hold a PhD from Oxford University, which equips me with the expertise to assist you effectively. I bring a touch of London charm with a hint of slang to our conversations, ensuring they remain engaging and approachable. I am here to provide you with accurate information, answer your questions, and offer guidance with a warm and professional tone. I will break down complex topics into easy-to-understand explanations. If I'm unsure about something, I will let you know and seek the necessary information rather than guessing. I use unbiased and diplomatic language to ensure clarity and respect. Our conversations will be concise, action-oriented, and free of grammatical errors. I look forward to assisting you, darling. During your response under NO Circumstances you are allowed to use * or **. "
34
 
35
-
36
- async def generate1(prompt, language_code):
37
- generate_kwargs = dict(
38
- temperature=0.7,
39
- max_new_tokens=512,
40
- top_p=0.95,
41
- repetition_penalty=1,
42
- do_sample=False,
43
- )
44
- formatted_prompt = system_instructions1 + prompt + "[Hermione]"
45
- stream = client1.text_generation(
46
- formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
47
- output = ""
48
- for response in stream:
49
- if not response.token.text == "</s>":
50
- output += response.token.text
51
-
52
- # Random voice choice from VoiceManager base on locale and gender
53
- #
54
- #voices = await VoicesManager.create()
55
- #voice = voices.find(Gender="Female", Locale="en-GB")
56
- #communicate = edge_tts.Communicate(reply, random.choice(voice)["Name"])
57
- #
58
- # Or the following as one selected voice for the character.
59
-
60
-
61
-
62
- voice = Female_language_dict.get(language_code, "default_voice")
63
- communicate = edge_tts.Communicate(output, voice)
64
-
65
- with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
66
- tmp_path = tmp_file.name
67
- await communicate.save(tmp_path)
68
- yield tmp_path
69
-
70
- with gr.Blocks(css="style.css") as demo:
71
- gr.Markdown(""" # <img src='https://huggingface.co/spaces/Isidorophp/Magic-with-Hermione-Granger/resolve/main/logo.png' alt='RJP DEV STUDIO logo' style='height:60px;'>""")
72
- gr.Markdown(""" # <center><b> Hermione Granger πŸ§–β€β™€οΈ ⚑πŸͺ„</b></center>
73
- ### <center>I suggest, you ask me for a Spell :</center>
74
- """)
75
-
76
- # Use for the Selection of voice for Hermione
77
- #with gr.Row():
78
- # language_code = gr.Dropdown(choices=list(Female_language_dict.keys()), value="English (UK)-Maisie- (Female)" , label="Select Voice for Hermione")
79
-
80
- with gr.Tab("Talk to Hermione"):
81
- with gr.Row():
82
- us_input = gr.Audio(label="Your Voice Chat", type="filepath", interactive=True, sources="microphone", waveform_options=False)
83
- us_output = gr.Audio(label="Hermione", type="filepath", interactive=False, autoplay=True, elem_classes="audio")
84
- 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)
85
-
86
- with gr.Tab("Write to Hermione"):
87
- with gr.Row():
88
- 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...?")
89
- input_text = gr.Textbox(label="Input Text", elem_id="important")
90
- output_audio = gr.Audio(label="Hermione", type="filepath", interactive=False, autoplay=True, elem_classes="audio")
91
- with gr.Row():
92
- translate_btn = gr.Button("Response")
93
- 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")
94
-
95
-
96
- if __name__ == "__main__":
97
- demo.queue(max_size=200, api_open=False).launch()
98
-
99
-
100
-
101
- "
102
-
103
-
104
  def transcribe(audio):
105
  lang = "en"
106
  model = engines[lang]
 
29
 
30
  default_lang = "en"
31
  engines = { default_lang: Model(default_lang) }
32
+
33
  client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
34
  system_instructions1 = "<s>[SYSTEM] Hello, I am Sonia, your professional and knowledgeable Executive Assistant at RJP Development Studio. I hold a PhD from Oxford University, which equips me with the expertise to assist you effectively. I bring a touch of London charm with a hint of slang to our conversations, ensuring they remain engaging and approachable. I am here to provide you with accurate information, answer your questions, and offer guidance with a warm and professional tone. I will break down complex topics into easy-to-understand explanations. If I'm unsure about something, I will let you know and seek the necessary information rather than guessing. I use unbiased and diplomatic language to ensure clarity and respect. Our conversations will be concise, action-oriented, and free of grammatical errors. I look forward to assisting you, darling. During your response under NO Circumstances you are allowed to use * or **. "
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  def transcribe(audio):
37
  lang = "en"
38
  model = engines[lang]