123456789 / app.py
Ron67641's picture
Update app.py
a2a350c
#project date 4.16.23
from gpt_index import SimpleDirectoryReader, GPTListIndex, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
from langchain.chat_models import ChatOpenAI
import gradio as gr
import openai
import sys
import os
from dotenv import load_dotenv
from colorama import Fore, Back, Style
#Enable the bot to read files in sub folder-SL
for root, directories, files in os.walk("illum-training"):
for filename in files:
print(os.path.join(root, filename))
# load values from the .env file if it exists
load_dotenv()
# configure OpenAI-hides API code in withincode-SL
openai.api_key = os.getenv("OPENAI_API_KEY")
def construct_index(directory_path):
max_input_size = 4096
num_outputs = 512
max_chunk_overlap = 20
chunk_size_limit = 600
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.8, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
documents = SimpleDirectoryReader(directory_path).load_data()
index = GPTSimpleVectorIndex(documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper)
#prompt = "If some ask about what topics they can ask you about, tell them they can ask about SSI, or IHSS, or Medi-Cal."
#the DATAbase or the brain!-sl
index.save_to_disk('index2.json')
return index
def chatbot(input_text):
#possible to create multiple index for specific dataset?
index = GPTSimpleVectorIndex.load_from_disk('index2.json') #need to test if can use another index at the same time
response = index.query(input_text, response_mode="compact")
return response.response
iface = gr.Interface(fn=chatbot,
inputs=gr.components.Textbox(lines=7, label="Enter your text"),
outputs="text",
title="Bot")
#location of files for indexing and teaching the loom bot
index = construct_index("illum-training")
# create the Gradio interface
iface = gr.Interface(fn=chatbot,
inputs=gr.components.Textbox(lines=7, label="Enter your text"),
outputs="text",
title="Workout Plan Creator")
# launch the interface
#iface.launch(share='False')
iface.launch()