import gradio as gr import random import time import boto3 from botocore import UNSIGNED from botocore.client import Config import zipfile from langchain.llms import HuggingFaceHub model_id = HuggingFaceHub(repo_id="HuggingFaceH4/zephyr-7b-beta", model_kwargs={"temperature":0.1, "max_new_tokens":1024}) from langchain.embeddings import HuggingFaceHubEmbeddings embeddings = HuggingFaceHubEmbeddings() from langchain.vectorstores import FAISS from langchain.chains import RetrievalQA s3 = boto3.client('s3', config=Config(signature_version=UNSIGNED)) s3.download_file('rad-rag-demos', 'vectorstores/faiss_db_ray.zip', './chroma_db/faiss_db_ray.zip') with zipfile.ZipFile('./chroma_db/faiss_db_ray.zip', 'r') as zip_ref: zip_ref.extractall('./chroma_db/') FAISS_INDEX_PATH='./chroma_db/faiss_db_ray' #embeddings = HuggingFaceHubEmbeddings("multi-qa-mpnet-base-dot-v1") embeddings = HuggingFaceHubEmbeddings() db = FAISS.load_local(FAISS_INDEX_PATH, embeddings) retriever = db.as_retriever(search_type = "mmr") global qa qa = RetrievalQA.from_chain_type(llm=model_id, chain_type="stuff", retriever=retriever) def add_text(history, text): history = history + [(text, None)] return history, "" def bot(history): response = infer(history[-1][0]) history[-1][1] = response['result'] return history def infer(question): query = question result = qa({"query": query}) return result css=""" #col-container {max-width: 700px; margin-left: auto; margin-right: auto;} """ title = """
The AI bot is here to help you with the RAY Documentation,
start asking questions about the open-source software