DaoAdvocate commited on
Commit ·
65932a8
1
Parent(s): 3c4778e
app.py
Browse files1234567import gradio as grdef greet(name):return "Hello " + name + "!!"iface = gr.Interface(fn=greet, inputs="text", outputs="text")iface.launch()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748import gradio as grimport osimport getpassfrom langchain.embeddings.openai import OpenAIEmbeddingsfrom langchain.chat_models import ChatOpenAIfrom langchain.chains import ConversationalRetrievalChainfrom langchain.vectorstores import DeepLakefrom dotenv import load_dotenvload_dotenv()os.environ.get("ACTIVELOOP_TOKEN")username = "rihp" # replace with your username from app.activeloop.aiprojectname = "polywrap5" # replace with your project name from app.activeloop.aiembeddings = OpenAIEmbeddings(disallowed_special=())db = DeepLake(dataset_path=f"hub://{username}/{projectname}", read_only=True, embedding_function=embeddings)retriever = db.as_retriever()retriever.search_kwargs['distance_metric'] = 'cos'retriever.search_kwargs['fetch_k'] = 100retriever.search_kwargs['maximal_marginal_relevance'] = Trueretriever.search_kwargs['k'] = 10model = ChatOpenAI(model_name='gpt-3.5-turbo') # switch to 'gpt-4'qa = ConversationalRetrievalChain.from_llm(model, retriever=retriever)def model(prompt):questions = [prompt]chat_history = []for question in questions:result = qa({"question": question, "chat_history": chat_history})chat_history.append((question, result['answer']))print(f"-> **Question**: {question} \n")print(f"**Answer**: {result['answer']} \n")return result['answer']iface = gr.Interface(fn=model, inputs="text", outputs="text")iface.launch()
app.py+44-3