CoolFace
Apppublic

Surpass/HelpChatbot

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py36 linesDownload Raw Back to root
1from gpt_index import SimpleDirectoryReader, GPTListIndex, GPTSimpleVectorIndex, LLMPredictor, PromptHelper2from langchain.chat_models import ChatOpenAI3import gradio as gr4import sys5import os6 7def construct_index(directory_path):8    max_input_size = 40969    num_outputs = 51210    max_chunk_overlap = 2011    chunk_size_limit = 60012 13    prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)14 15    llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.7, model_name="gpt-3.5-turbo", max_tokens=num_outputs))16 17    documents = SimpleDirectoryReader(directory_path).load_data()18 19    index = GPTSimpleVectorIndex(documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper)20 21    index.save_to_disk('index.json')22 23    return index24 25def chatbot(input_text):26    index = GPTSimpleVectorIndex.load_from_disk('index.json')27    response = index.query(input_text, response_mode="compact")28    return response.response29 30iface = gr.Interface(fn=chatbot,31                     inputs=gr.components.Textbox(lines=7, label="Enter your question"),32                     outputs="text",33                     title="Surpass Custom-trained AI Chatbot")34 35#index = construct_index("help.surpass.com")36iface.launch()#share=True)