Interrobangarang commited on
Commit
9d3e733
·
1 Parent(s): 5d07fc9

Upload 3 files

Browse files
Files changed (3) hide show
  1. PDFminer.py +40 -0
  2. app.py +12 -0
  3. requirements.txt +3 -0
PDFminer.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from gpt_index import SimpleDirectoryReader, GPTListIndex, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
3
+ from langchain.chat_models import ChatOpenAI
4
+ import gradio as gr
5
+ import sys
6
+ import os
7
+
8
+ os.environ["openai_api_key"] = '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'
9
+
10
+ def construct_index(directory_path):
11
+ max_input_size = 4096
12
+ num_outputs = 512
13
+ max_chunk_overlap = 20
14
+ chunk_size_limit = 600
15
+
16
+ prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
17
+
18
+ llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.7, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
19
+
20
+ documents = SimpleDirectoryReader(directory_path).load_data()
21
+
22
+ index = GPTSimpleVectorIndex(documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper)
23
+
24
+ index.save_to_disk('index.json')
25
+
26
+ return index
27
+
28
+ def chatbot(input_text):
29
+ index = GPTSimpleVectorIndex.load_from_disk('index.json')
30
+ response = index.query(input_text, response_mode="compact")
31
+ return response.response
32
+
33
+ iface = gr.Interface(fn=chatbot,
34
+ inputs=gr.components.Textbox(lines=7, label="Enter your text"),
35
+ outputs="text",
36
+ title="Custom-trained AI Chatbot")
37
+
38
+ # Change the argument to point to "C:\temp" instead of "docs"
39
+ index = construct_index(r"C:\Temp\AI Training")
40
+ iface.launch(share=True)
app.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+
4
+ def chatbot(input_text):
5
+ index = GPTSimpleVectorIndex.load_from_disk('index.json')
6
+ response = index.query(input_text, response_mode="compact")
7
+ return response.response
8
+
9
+ iface = gr.Interface(fn=chatbot,
10
+ inputs=gr.components.Textbox(lines=7, label="Enter your text"),
11
+ outputs="text",
12
+ title="Custom-trained AI Chatbot")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gpt_index
2
+ langchain.chat_models
3
+ gradio