File size: 883 Bytes
7e1807d
 
 
 
 
 
 
 
 
 
75708e7
 
da1505f
7e1807d
75708e7
7e1807d
 
 
 
 
 
75708e7
211be8b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from transformers import pipeline
from langchain_cohere import ChatCohere
from langchain_core.messages import HumanMessage, SystemMessage 
from langchain_core.output_parsers import StrOutputParser
import gradio as gr

llm = ChatCohere(model='command-r')
pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base")
parser = StrOutputParser()

def getting_prompt(doclist,spkmsg):
    print(spkmsg)
    recog_text = pipe(spkmsg)
    messages = [
        SystemMessage(content='You are A helpful AI assistant and will provide truthful information from the context and your knowledge if you are prompted.'),
        HumanMessage(content=recog_text['text']),
    ]
    chain = llm | parser
    response = chain.invoke(messages)
    return response

demo = gr.Interface(getting_prompt,['file',gr.Audio(sources="microphone",type='filepath')],'text')
demo.launch(debug=True)