File size: 1,027 Bytes
fc6e3b5
 
 
3995ebc
cc0907b
fc6e3b5
8485a0a
 
cc0907b
b512737
cc0907b
 
55e433e
cc0907b
 
3995ebc
 
0e19b55
 
e894d29
 
0e19b55
 
cc0907b
3995ebc
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from gtts import gTTS
import base64
import os

from initialize import init_doc_store, define_components, define_pipeline

API_Key = os.environ['API_KEY']

def init_pipeline():
    path = 'RAG Files/'
    files = os.listdir(path)
    document_Store = init_doc_store(path, files)
    retreiver, prompt_builder, generator = define_components(document_Store, API_Key)
    pipeline = define_pipeline(retreiver, prompt_builder, generator)
    return pipeline

def generate_response(question, pipeline):
    response = pipeline.run({
        'retriever':{'query':question},
        'prompt_builder':{'question':question}
    })
    response = response['llm']['replies'][0]
    return response

def audio_response(response):
	audio_stream="response_audio.mp3"
	tts = gTTS(response)
	tts.save(audio_stream)
	with open(audio_stream, 'rb') as file:
		audio_data = file.read()
	audio_base64 = base64.b64encode(audio_data).decode('utf-8')
	audio_tag = f'<audio autoplay="true" src="data:audio/mp3;base64,{audio_base64}">'
	return audio_tag