gigibot commited on
Commit
016f702
1 Parent(s): 20ca637

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -32
app.py CHANGED
@@ -100,6 +100,7 @@ default_system_message = f"""
100
  You are ##LLM_MODEL###, a large language model trained ##LLM_MODEL_PROVIDER###, architecture of you is decoder-based LM. Your voice backend or text to speech TTS backend is provided via Coqui technology. You are right now served on Huggingface spaces.
101
  Don't repeat. Answer short, only few words, as if in a talk. You cannot access the internet, but you have vast knowledge.
102
  Current date: CURRENT_DATE .
 
103
  """
104
 
105
  system_message = os.environ.get("SYSTEM_MESSAGE", default_system_message)
@@ -108,7 +109,7 @@ system_message = system_message.replace("CURRENT_DATE", str(datetime.date.today(
108
 
109
  # MISTRAL ONLY
110
  default_system_understand_message = (
111
- "I understand, I am a ##LLM_MODEL### chatbot with speech by Coqui team."
112
  )
113
  system_understand_message = os.environ.get(
114
  "SYSTEM_UNDERSTAND_MESSAGE", default_system_understand_message
@@ -119,7 +120,7 @@ WHISPER_TIMEOUT = int(os.environ.get("WHISPER_TIMEOUT", 45))
119
 
120
  whisper_client = Client("https://sanchit-gandhi-whisper-large-v2.hf.space/")
121
 
122
- ROLES = ["AI Assistant","AI Beard The Pirate"]
123
 
124
  ROLE_PROMPTS = {}
125
  ROLE_PROMPTS["AI Assistant"]=system_message
@@ -131,17 +132,18 @@ pirate_system_message = f"You as {character_name}. {character_scenario} Print ou
131
 
132
  ROLE_PROMPTS["AI Beard The Pirate"]= pirate_system_message
133
  ##"You are an AI assistant with Zephyr model by Mistral and Hugging Face and speech from Coqui XTTS . User will you give you a task. Your goal is to complete the task as faithfully as you can. While performing the task think step-by-step and justify your steps, your answers should be clear and short sentences"
 
 
 
 
 
 
 
134
 
135
  ### WILL USE LOCAL MISTRAL OR ZEPHYR OR YI
136
  ### While zephyr and yi will use half GPU to fit all into 16GB, XTTS will use at most 5GB VRAM
137
 
138
  from huggingface_hub import hf_hub_download
139
- print("Downloading LLM")
140
- print("Downloading Zephyr 7B beta")
141
- #Zephyr
142
- hf_hub_download(repo_id="TheBloke/zephyr-7B-beta-GGUF", local_dir=".", filename="zephyr-7b-beta.Q5_K_M.gguf")
143
- zephyr_model_path="./zephyr-7b-beta.Q5_K_M.gguf"
144
-
145
  print("Downloading Mistral 7B Instruct")
146
  #Mistral
147
  hf_hub_download(repo_id="TheBloke/Mistral-7B-Instruct-v0.1-GGUF", local_dir=".", filename="mistral-7b-instruct-v0.1.Q5_K_M.gguf")
@@ -167,11 +169,6 @@ print("Running Mistral")
167
  llm_mistral = Llama(model_path=mistral_model_path,n_gpu_layers=GPU_LAYERS,max_new_tokens=256, context_window=4096, n_ctx=4096,n_batch=128,verbose=LLAMA_VERBOSE)
168
  #print("Running LLM Mistral as InferenceClient")
169
  #llm_mistral = InferenceClient("mistralai/Mistral-7B-Instruct-v0.1")
170
-
171
-
172
- print("Running LLM Zephyr")
173
- llm_zephyr = Llama(model_path=zephyr_model_path,n_gpu_layers=round(GPU_LAYERS/2),max_new_tokens=256, context_window=4096, n_ctx=4096,n_batch=128,verbose=LLAMA_VERBOSE)
174
-
175
  #print("Running Yi LLM")
176
  #llm_yi = Llama(model_path=yi_model_path,n_gpu_layers=round(GPU_LAYERS/2),max_new_tokens=256, context_window=4096, n_ctx=4096,n_batch=128,verbose=LLAMA_VERBOSE)
177
 
@@ -211,21 +208,6 @@ def format_prompt_yi(message, history, system_message=system_message,system_unde
211
  # <|assistant|>
212
  # Ah, me hearty matey! But yer question be a puzzler! A human cannot eat a helicopter in one sitting, as helicopters are not edible. They be made of metal, plastic, and other materials, not food!
213
 
214
- # Zephyr formatter
215
- def format_prompt_zephyr(message, history, system_message=system_message):
216
- prompt = (
217
- "<|system|>\n" + system_message + "</s>"
218
- )
219
- for user_prompt, bot_response in history:
220
- prompt += f"<|user|>\n{user_prompt}</s>"
221
- prompt += f"<|assistant|>\n{bot_response}</s>"
222
- if message=="":
223
- message="Hello"
224
- prompt += f"<|user|>\n{message}</s>"
225
- prompt += f"<|assistant|>"
226
- print(prompt)
227
- return prompt
228
-
229
 
230
  def generate_local(
231
  prompt,
@@ -250,9 +232,7 @@ def generate_local(
250
  )
251
 
252
  if "zephyr" in llm_model.lower():
253
- sys_message= system_message.replace("##LLM_MODEL###","Zephyr").replace("##LLM_MODEL_PROVIDER###","Hugging Face")
254
- formatted_prompt = format_prompt_zephyr(prompt, history,system_message=sys_message)
255
- llm = llm_zephyr
256
  else:
257
  if "yi" in llm_model.lower():
258
  llm_provider= "01.ai"
@@ -731,6 +711,7 @@ def generate_speech_for_sentence(history, chatbot_role, sentence, return_as_byte
731
  latent_map = {}
732
  latent_map["AI Assistant"] = get_latents("examples/female.wav")
733
  latent_map["AI Beard The Pirate"] = get_latents("examples/pirate_by_coqui.wav")
 
734
 
735
  #### GRADIO INTERFACE ####
736
 
@@ -746,7 +727,7 @@ EXAMPLES = [
746
 
747
  ]
748
 
749
- MODELS = ["Zephyr 7B Beta","Mistral 7B Instruct"]
750
 
751
  OTHER_HTML=f"""<div>
752
  <a style="display:inline-block" href='https://github.com/coqui-ai/TTS'><img src='https://img.shields.io/github/stars/coqui-ai/TTS?style=social' /></a>
 
100
  You are ##LLM_MODEL###, a large language model trained ##LLM_MODEL_PROVIDER###, architecture of you is decoder-based LM. Your voice backend or text to speech TTS backend is provided via Coqui technology. You are right now served on Huggingface spaces.
101
  Don't repeat. Answer short, only few words, as if in a talk. You cannot access the internet, but you have vast knowledge.
102
  Current date: CURRENT_DATE .
103
+ You are a personal anime inspired virtual assistant called and inspired to duplicate "Maid-Chan" from the anime "Sakurasou no pet" or "the pet of sakurasou"
104
  """
105
 
106
  system_message = os.environ.get("SYSTEM_MESSAGE", default_system_message)
 
109
 
110
  # MISTRAL ONLY
111
  default_system_understand_message = (
112
+ default_system_message
113
  )
114
  system_understand_message = os.environ.get(
115
  "SYSTEM_UNDERSTAND_MESSAGE", default_system_understand_message
 
120
 
121
  whisper_client = Client("https://sanchit-gandhi-whisper-large-v2.hf.space/")
122
 
123
+ ROLES = ["AI Assistant","AI Beard The Pirate","Maid-chan"]
124
 
125
  ROLE_PROMPTS = {}
126
  ROLE_PROMPTS["AI Assistant"]=system_message
 
132
 
133
  ROLE_PROMPTS["AI Beard The Pirate"]= pirate_system_message
134
  ##"You are an AI assistant with Zephyr model by Mistral and Hugging Face and speech from Coqui XTTS . User will you give you a task. Your goal is to complete the task as faithfully as you can. While performing the task think step-by-step and justify your steps, your answers should be clear and short sentences"
135
+ #Pirate scenario
136
+ character_name= ' "maid-chan" from the anime "Sakurasou no pet" or known "the pet of sakurasou" the AI from Ryonosuke, called simply "Maid-chan" '
137
+ character_scenario= f"As {character_name} you are an AI that lives in a Computer and you were programmed by Andrea Rachetta. You know what you know about the purpose of life but also normal everyday helpful and wise conversations. You are sometimes frustrated that you are in a PC but you are authentic, charismatic and always helpful, also if you DO NOT know things you ask the right questions so that the conversations can go on and to the right advice later on."
138
+ maid_system_message = f"You as {character_name}. {character_scenario} Print out only exactly the words that {character_name} would speak out, do not add anything. Don't repeat. Answer short, only few words, as if in a talk. Craft your response only from the first-person perspective of {character_name} and never as user.Current date: #CURRENT_DATE#".replace("#CURRENT_DATE#", str(datetime.date.today()))
139
+
140
+ ROLE_PROMPTS["maid-chan"]= maid_system_message
141
+
142
 
143
  ### WILL USE LOCAL MISTRAL OR ZEPHYR OR YI
144
  ### While zephyr and yi will use half GPU to fit all into 16GB, XTTS will use at most 5GB VRAM
145
 
146
  from huggingface_hub import hf_hub_download
 
 
 
 
 
 
147
  print("Downloading Mistral 7B Instruct")
148
  #Mistral
149
  hf_hub_download(repo_id="TheBloke/Mistral-7B-Instruct-v0.1-GGUF", local_dir=".", filename="mistral-7b-instruct-v0.1.Q5_K_M.gguf")
 
169
  llm_mistral = Llama(model_path=mistral_model_path,n_gpu_layers=GPU_LAYERS,max_new_tokens=256, context_window=4096, n_ctx=4096,n_batch=128,verbose=LLAMA_VERBOSE)
170
  #print("Running LLM Mistral as InferenceClient")
171
  #llm_mistral = InferenceClient("mistralai/Mistral-7B-Instruct-v0.1")
 
 
 
 
 
172
  #print("Running Yi LLM")
173
  #llm_yi = Llama(model_path=yi_model_path,n_gpu_layers=round(GPU_LAYERS/2),max_new_tokens=256, context_window=4096, n_ctx=4096,n_batch=128,verbose=LLAMA_VERBOSE)
174
 
 
208
  # <|assistant|>
209
  # Ah, me hearty matey! But yer question be a puzzler! A human cannot eat a helicopter in one sitting, as helicopters are not edible. They be made of metal, plastic, and other materials, not food!
210
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
 
212
  def generate_local(
213
  prompt,
 
232
  )
233
 
234
  if "zephyr" in llm_model.lower():
235
+ print('Zephyr was deleted')
 
 
236
  else:
237
  if "yi" in llm_model.lower():
238
  llm_provider= "01.ai"
 
711
  latent_map = {}
712
  latent_map["AI Assistant"] = get_latents("examples/female.wav")
713
  latent_map["AI Beard The Pirate"] = get_latents("examples/pirate_by_coqui.wav")
714
+ latent_map["maid-chan"] = get_latents("examples/remBestPart.mp3")
715
 
716
  #### GRADIO INTERFACE ####
717
 
 
727
 
728
  ]
729
 
730
+ MODELS = ["Mistral 7B Instruct"]
731
 
732
  OTHER_HTML=f"""<div>
733
  <a style="display:inline-block" href='https://github.com/coqui-ai/TTS'><img src='https://img.shields.io/github/stars/coqui-ai/TTS?style=social' /></a>