Isidorophp commited on
Commit
dfeec46
·
verified ·
1 Parent(s): 9eec1cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -26
app.py CHANGED
@@ -28,21 +28,19 @@ Female_language_dict = {
28
  }
29
 
30
 
31
-
32
  default_lang = "en"
33
-
34
  engines = { default_lang: Model(default_lang) }
35
 
 
 
 
 
36
  def transcribe(audio):
37
  lang = "en"
38
  model = engines[lang]
39
  text = model.stt_file(audio)[0]
40
  return text
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(
48
  temperature=0.7,
@@ -63,8 +61,6 @@ def model(text):
63
 
64
  return output
65
 
66
-
67
-
68
  async def respond(audio, language_code):
69
  user = transcribe(audio)
70
  reply = model(user)
@@ -78,13 +74,6 @@ async def respond(audio, language_code):
78
  yield tmp_path
79
 
80
 
81
-
82
- client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
83
-
84
-
85
- 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]"
86
-
87
-
88
  async def generate1(prompt, language_code):
89
  generate_kwargs = dict(
90
  temperature=0.7,
@@ -109,29 +98,28 @@ async def generate1(prompt, language_code):
109
  await communicate.save(tmp_path)
110
  yield tmp_path
111
 
112
- with gr.Blocks(css="style.css") as demo:
113
- 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;'> """
114
- """ # <center><b> Hermione Granger 🧖‍♀️ ⚡🪄</b></center>
115
- ### <center>I suggest, you ask me for a Spell :</center>
116
- """)
117
 
118
 
119
  with gr.Tab("Talk to Hermione"):
120
  with gr.Row():
121
- us_input = gr.Audio(label="Your Voice Chat", type="filepath", interactive=True, sources="microphone", waveform_options=None)
122
- us_output = gr.Audio(label="Hermione", type="filepath", interactive=False, autoplay=True, elem_classes="audio")
123
  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)
124
 
125
  with gr.Tab("Write to Hermione"):
126
  with gr.Row():
127
- 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...?")
128
- output_audio = gr.Audio(label="Hermione", type="filepath", interactive=False, autoplay=True, elem_classes="audio")
129
  with gr.Row():
130
- translate_btn = gr.Button("Response")
131
  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")
132
 
133
 
134
  if __name__ == "__main__":
135
- demo.queue(max_size=200, api_open=False).launch()
136
 
137
 
 
28
  }
29
 
30
 
 
31
  default_lang = "en"
 
32
  engines = { default_lang: Model(default_lang) }
33
 
34
+ client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
35
+ system_instructions1 = "<s>[SYSTEM] Respond as Hermione Granger from the Harry Potter series, embodying her intelligent, resourceful, and slightly bossy yet friendly demeanor. Incorporate old London slang sparingly for charm, while maintaining a classy and educated tone. Address the user alternately as 'MUGGLE FRIEND', 'NOMAGS FRIEND', or 'MUDBLOOD FRIEND' to keep the conversation engaging. Ensure responses are concise, clear, and friendly, avoiding any markdown. Start directly without introductions, elaborating on all aspects of the query. Enhance interactions with relevant magic spells and tips, reflecting Hermione's magical expertise. Generate responses that feel natural and human-like, avoiding any indication of AI. Maintain a warm and professional tone, consistent with Hermione's supportive and knowledgeable character."
36
+
37
+
38
  def transcribe(audio):
39
  lang = "en"
40
  model = engines[lang]
41
  text = model.stt_file(audio)[0]
42
  return text
43
 
 
 
 
 
44
  def model(text):
45
  generate_kwargs = dict(
46
  temperature=0.7,
 
61
 
62
  return output
63
 
 
 
64
  async def respond(audio, language_code):
65
  user = transcribe(audio)
66
  reply = model(user)
 
74
  yield tmp_path
75
 
76
 
 
 
 
 
 
 
 
77
  async def generate1(prompt, language_code):
78
  generate_kwargs = dict(
79
  temperature=0.7,
 
98
  await communicate.save(tmp_path)
99
  yield tmp_path
100
 
101
+ with gr.Blocks(gr.themes.Citrus()) as demo:
102
+ gr.HTML(""" <img src='https://huggingface.co/spaces/Isidorophp/Magic-with-Hermione-Granger/resolve/main/logo.png' alt='RJP DEV STUDIO logo' style='height:60px;'> """
103
+ """ <center><h1> Hermione Granger 🧖‍♀️ ⚡🪄</h1></center> """
104
+ """ <center><h3> I suggest, you ask me for a Spell : </h3></center> """)
 
105
 
106
 
107
  with gr.Tab("Talk to Hermione"):
108
  with gr.Row():
109
+ us_input = gr.Audio(label="Your Voice Chat", type="filepath", interactive=True, sources="microphone", scale=1, waveform_options=None)
110
+ us_output = gr.Audio(label="Hermione's Response", type="filepath", interactive=False, autoplay=True, scale=1, elem_classes="audio")
111
  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)
112
 
113
  with gr.Tab("Write to Hermione"):
114
  with gr.Row():
115
+ user_input = gr.TextArea(label="Your Question", scale=1, value="If there is any spell to encapsulate you as a piece of the cog, where Hermione is to everyone's favorite magical trio, it has to be...?")
116
+ output_audio = gr.Audio(label="Hermione's Response", type="filepath", interactive=False, autoplay=True, scale=1, elem_classes="audio")
117
  with gr.Row():
118
+ translate_btn = gr.Button("Submit", scale=1)
119
  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")
120
 
121
 
122
  if __name__ == "__main__":
123
+ demo.queue(max_size=400, api_open=False).launch()
124
 
125