import gradio as gr import whisper from transformers import pipeline model = whisper.load_model("base") sentiment_analysis = pipeline("sentiment-analysis", framework="pt", model="SamLowe/roberta-base-go_emotions") import gradio as gr import whisper from transformers import pipeline import gradio as gr import pandas as pd from io import StringIO import os,re from langchain.llms import OpenAI import pandas as pd from langchain.document_loaders import UnstructuredPDFLoader from langchain.prompts import PromptTemplate from langchain.chains import LLMChain from langchain.embeddings.openai import OpenAIEmbeddings from langchain.vectorstores import Chroma from langchain.text_splitter import CharacterTextSplitter from langchain.llms import OpenAI from langchain.chains import RetrievalQA from langchain.document_loaders import TextLoader from langchain.prompts import PromptTemplate from langchain.callbacks.stdout import StdOutCallbackHandler from langchain.chat_models.openai import ChatOpenAI from langchain.prompts.prompt import PromptTemplate from langchain.llms import OpenAI from langchain.prompts import PromptTemplate from langchain.chains import LLMChain model = whisper.load_model("base") sentiment_analysis = pipeline("sentiment-analysis", framework="pt", model="SamLowe/roberta-base-go_emotions") def predict(text): # loader = UnstructuredPDFLoader(file_obj.orig_name) # data = loader.load() # text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0) # texts = text_splitter.split_documents(data) # embeddings = OpenAIEmbeddings() # docsearch = Chroma.from_documents(texts, embeddings) # qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="map_reduce", retriever=docsearch.as_retriever()) prompt_template = """Ignore all previous instructions. You are the world's hearing aid company markerting agent. I am going to give you a text of a customer. Analyze it and you have 4 products in list which you have to suggest to the customer: ampli-mini it is mainly works for Maximum comfort and discretion, ampli-connect it is mainly works for Connected to the things you love, ampli-energy it is mainly works for Full of energy, like you, ampli-easy it is mainly works for Allow yourself to hear well. You can also be creative, funny, or show emotions at time. also share the book a appointment link of your company https://www.amplifon.com/uk/book-an-appointment Question: {question} Product details:""" prompt_template_lang = """ You are the world's best languages translator. Will give you some text or paragraph which you have to convert into Tamil, Hindi, Kannada and French. Input Text: {text} Tamil: Hindi: Kannada: French: """ PROMPT = PromptTemplate( template=prompt_template, input_variables=["question"] ) PROMPT_lang = PromptTemplate( template=prompt_template_lang, input_variables=["text"] ) # chain_type_kwargs = {"prompt": PROMPT} # qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=docsearch.as_retriever(), chain_type_kwargs=chain_type_kwargs) #Actually, Hi, how are you doing? Actually, I am looking for the hearing aid for my grandfather. He has like age around 62, 65 year old and one of the like major thing that I am looking for the hearing aid product which is like maximum comfort. So if you have anything in that category, so can you please tell me? Thank you. llm = OpenAI() # prompt = PromptTemplate( # input_variables=["product"], # template="What is a good name for a company that makes {product}?", # ) chain = LLMChain(llm=llm, prompt=PROMPT) chain_lang = LLMChain(llm=llm, prompt=PROMPT_lang) resp = chain.run(question=text) resp_lang = chain_lang.run(text=resp) # print(resp) # response = [] # category = ["ampli-mini", "ampli-connect", "ampli-energy", "ampli-easy"] # for value in category: # response.append({value:ai(qa, value)}) # html_output = "" # for obj in response: # # Loop through the key-value pairs in the object # for key, value in obj.items(): # value = re.sub(r'[\d\.]+', '', value) # value_list = value.strip().split('\n') # value_html = "