Delete app.py
Browse files
app.py
DELETED
@@ -1,48 +0,0 @@
|
|
1 |
-
from gpt_index import SimpleDirectoryReader, GPTListIndex, GPTSimpleVectorIndex, LLMPredictor, PromptHelper, ServiceContext
|
2 |
-
from langchain import OpenAI
|
3 |
-
import gradio as gr
|
4 |
-
import sys
|
5 |
-
import os
|
6 |
-
|
7 |
-
os.environ["OPENAI_API_KEY"] = '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'
|
8 |
-
|
9 |
-
def construct_index(directory_path):
|
10 |
-
max_input_size = 4096
|
11 |
-
num_outputs = 512
|
12 |
-
max_chunk_overlap = 20
|
13 |
-
chunk_size_limit = 600
|
14 |
-
|
15 |
-
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
|
16 |
-
|
17 |
-
#llm_predictor = LLMPredictor(llm=OpenAI(temperature=0.4, model_name="text-davinci-003", max_tokens=num_outputs))
|
18 |
-
llm_predictor = LLMPredictor(llm=OpenAI(temperature=0.2, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
|
19 |
-
|
20 |
-
|
21 |
-
service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper)
|
22 |
-
|
23 |
-
documents = SimpleDirectoryReader(directory_path).load_data()
|
24 |
-
|
25 |
-
index = GPTSimpleVectorIndex.from_documents(documents, service_context=service_context) #, llm_predictor=llm_predictor, prompt_helper=prompt_helper)
|
26 |
-
|
27 |
-
index.save_to_disk('index.json')
|
28 |
-
|
29 |
-
return index
|
30 |
-
|
31 |
-
def chatbot(input_text):
|
32 |
-
index = GPTSimpleVectorIndex.load_from_disk('index.json')
|
33 |
-
response = index.query(input_text, response_mode="compact")
|
34 |
-
return response.response
|
35 |
-
|
36 |
-
iface = gr.Interface(fn=chatbot,
|
37 |
-
inputs=gr.inputs.Textbox(lines=7, label="Enter your text"),
|
38 |
-
outputs="text",
|
39 |
-
title="Tikehau-trained AI Chatbot")
|
40 |
-
|
41 |
-
index = construct_index("docs")
|
42 |
-
iface.launch(share=True)
|
43 |
-
# Press the green button in the gutter to run the script.
|
44 |
-
# if __name__ == '__main__':
|
45 |
-
# index = construct_index("docs")
|
46 |
-
# iface.launch(share=True)
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|