| 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) | |