Spaces:
Runtime error
Runtime error
Shrirang20
commited on
Commit
•
0cae3f7
1
Parent(s):
84334cd
Update app.py
Browse files
app.py
CHANGED
@@ -79,7 +79,7 @@ pages = loader.load_and_split(text_splitter=text_splitter)
|
|
79 |
pages_chunks = [page.page_content for page in pages]
|
80 |
print(f"Generated {len(pages_chunks)} chunks of {pm_kisan_doc}")
|
81 |
|
82 |
-
pages_chunks[8]
|
83 |
|
84 |
embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
|
85 |
|
@@ -107,9 +107,7 @@ def get_gemini_output(prompt, temperature=0.6):
|
|
107 |
|
108 |
genai.configure(api_key= gemini_api_key)
|
109 |
model = genai.GenerativeModel(model_name='gemini-pro')
|
110 |
-
answer = model.generate_content(prompt
|
111 |
-
generation_config=genai.types.GenerationConfig(
|
112 |
-
temperature=0.1))
|
113 |
|
114 |
return answer.text
|
115 |
|
@@ -235,7 +233,7 @@ def run_tts(text, tts_lang):
|
|
235 |
tts_lang = lang_map[tts_lang]
|
236 |
print(f"Lang code: {tts_lang}")
|
237 |
|
238 |
-
|
239 |
tts_command = f'python3 -m TTS.bin.synthesize --text "{text}" \
|
240 |
--model_path /models/v1/{tts_lang}/fastpitch/best_model.pth \
|
241 |
--config_path /models/v1/{tts_lang}/fastpitch/config.json \
|
@@ -254,7 +252,7 @@ def run_tts(text, tts_lang):
|
|
254 |
|
255 |
os.system(tts_command)
|
256 |
|
257 |
-
|
258 |
def download_ai4b_asr_model(lang: str):
|
259 |
|
260 |
available_langs = {
|
@@ -285,11 +283,10 @@ def download_ai4b_asr_model(lang: str):
|
|
285 |
url = f"https://objectstore.e2enetworks.net/indic-asr-public/indicConformer/ai4b_indicConformer_{available_langs[lang]}.nemo"
|
286 |
try:
|
287 |
result= subprocess.run(['wget', url, '-O', download_path], check=True, capture_output=True, text=True)
|
288 |
-
print(result.stdout)
|
289 |
except subprocess.CallProcessError as e:
|
290 |
print(f"Error occured: {e.stderr}")
|
291 |
raise
|
292 |
-
|
293 |
|
294 |
return download_path
|
295 |
|
@@ -309,14 +306,14 @@ ensure_numpy_version()
|
|
309 |
subprocess.run(['pip', 'install', 'numba==0.60.0'], check=True)
|
310 |
|
311 |
|
312 |
-
import librosa
|
313 |
|
314 |
-
def preprocess_audio(audio_path):
|
315 |
-
|
316 |
-
|
317 |
|
318 |
def transcribe(audio: str, lang: str):
|
319 |
-
audio, sr = preprocess_audio(audio)
|
320 |
|
321 |
lang_map = {
|
322 |
"odia": "or",
|
@@ -361,26 +358,12 @@ def process_user_query(user_query, retrieved_doc):
|
|
361 |
|
362 |
prompt = prompt_template.format(user_query=user_query, retrieved_doc=retrieved_doc)
|
363 |
print("Input prompt:", prompt)
|
|
|
364 |
processed_doc = get_gemini_output(prompt)
|
365 |
print("Output prompt:",processed_doc)
|
366 |
|
367 |
return processed_doc
|
368 |
|
369 |
-
#Context awareness
|
370 |
-
# from collections import deque
|
371 |
-
|
372 |
-
# class ContextManger:
|
373 |
-
# def __init__(self,max_history=7):
|
374 |
-
# self.history = deque(maxlen=max_history)
|
375 |
-
|
376 |
-
# def add_interaction(self,query,response):
|
377 |
-
# self.history.append((query,response))
|
378 |
-
|
379 |
-
# def get_context(self):
|
380 |
-
# return list(self.history)
|
381 |
-
|
382 |
-
# context_manager = ContextManger()
|
383 |
-
|
384 |
|
385 |
import traceback
|
386 |
|
@@ -393,7 +376,6 @@ def process_gradio_input(audio, user_lang):
|
|
393 |
# Convert the Indic text from transcription to English, so that GPT-3.5 can process it
|
394 |
print(f"Translating indic to en..")
|
395 |
indic_to_en = indic_translate(src_lang=user_lang, tgt_lang="english", sents_to_translate=[query_transcription])[0]
|
396 |
-
print("IIIIIIIIIIIIIIINNNNNNNNNNNNNNDDDDIIIIIIIICCCCCCCCC_TRANSLATE:",indic_to_en)
|
397 |
|
398 |
|
399 |
# context = context_manager.get_context()
|
@@ -425,6 +407,7 @@ def process_gradio_input(audio, user_lang):
|
|
425 |
run_tts(text=en_to_indic_doc, tts_lang=user_lang)
|
426 |
print("Finished running TTS")
|
427 |
|
|
|
428 |
audio_outfile_path = "tts_output.wav"
|
429 |
|
430 |
|
|
|
79 |
pages_chunks = [page.page_content for page in pages]
|
80 |
print(f"Generated {len(pages_chunks)} chunks of {pm_kisan_doc}")
|
81 |
|
82 |
+
# pages_chunks[8]
|
83 |
|
84 |
embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
|
85 |
|
|
|
107 |
|
108 |
genai.configure(api_key= gemini_api_key)
|
109 |
model = genai.GenerativeModel(model_name='gemini-pro')
|
110 |
+
answer = model.generate_content(prompt)
|
|
|
|
|
111 |
|
112 |
return answer.text
|
113 |
|
|
|
233 |
tts_lang = lang_map[tts_lang]
|
234 |
print(f"Lang code: {tts_lang}")
|
235 |
|
236 |
+
print("TTS WORKING DIRECTORY:",os.getcwd())
|
237 |
tts_command = f'python3 -m TTS.bin.synthesize --text "{text}" \
|
238 |
--model_path /models/v1/{tts_lang}/fastpitch/best_model.pth \
|
239 |
--config_path /models/v1/{tts_lang}/fastpitch/config.json \
|
|
|
252 |
|
253 |
os.system(tts_command)
|
254 |
|
255 |
+
os.makedirs('asr_models', exist_ok=True)
|
256 |
def download_ai4b_asr_model(lang: str):
|
257 |
|
258 |
available_langs = {
|
|
|
283 |
url = f"https://objectstore.e2enetworks.net/indic-asr-public/indicConformer/ai4b_indicConformer_{available_langs[lang]}.nemo"
|
284 |
try:
|
285 |
result= subprocess.run(['wget', url, '-O', download_path], check=True, capture_output=True, text=True)
|
286 |
+
print("ASR MODEL DOWNLOADED SUCCESSFULLY",result.stdout)
|
287 |
except subprocess.CallProcessError as e:
|
288 |
print(f"Error occured: {e.stderr}")
|
289 |
raise
|
|
|
290 |
|
291 |
return download_path
|
292 |
|
|
|
306 |
subprocess.run(['pip', 'install', 'numba==0.60.0'], check=True)
|
307 |
|
308 |
|
309 |
+
# import librosa
|
310 |
|
311 |
+
# def preprocess_audio(audio_path):
|
312 |
+
# audio,sr = librosa.load(audio_path,sr=None,mono=True)
|
313 |
+
# return audio, sr
|
314 |
|
315 |
def transcribe(audio: str, lang: str):
|
316 |
+
# audio, sr = preprocess_audio(audio)
|
317 |
|
318 |
lang_map = {
|
319 |
"odia": "or",
|
|
|
358 |
|
359 |
prompt = prompt_template.format(user_query=user_query, retrieved_doc=retrieved_doc)
|
360 |
print("Input prompt:", prompt)
|
361 |
+
|
362 |
processed_doc = get_gemini_output(prompt)
|
363 |
print("Output prompt:",processed_doc)
|
364 |
|
365 |
return processed_doc
|
366 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
|
368 |
import traceback
|
369 |
|
|
|
376 |
# Convert the Indic text from transcription to English, so that GPT-3.5 can process it
|
377 |
print(f"Translating indic to en..")
|
378 |
indic_to_en = indic_translate(src_lang=user_lang, tgt_lang="english", sents_to_translate=[query_transcription])[0]
|
|
|
379 |
|
380 |
|
381 |
# context = context_manager.get_context()
|
|
|
407 |
run_tts(text=en_to_indic_doc, tts_lang=user_lang)
|
408 |
print("Finished running TTS")
|
409 |
|
410 |
+
print("PRESENT WORKING DIRECTORY OF AUDIO SAVED:", os.getcwd())
|
411 |
audio_outfile_path = "tts_output.wav"
|
412 |
|
413 |
|