stephenmccartney1234 commited on
Commit
863468c
·
verified ·
1 Parent(s): 78c7928

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -35
app.py CHANGED
@@ -1,47 +1,25 @@
1
- from gpt_index import SimpleDirectoryReader, GPTListIndex, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
2
- import os
3
- from langchain.chat_models import ChatOpenAI
4
  import gradio as gr
5
- from gpt_index import SimpleDirectoryReader, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
6
-
7
  import sys
8
-
9
- llm = ChatOpenAI(temperature=0.7, model_name="gpt-3.5-turbo-instruct", engine="gpt-3.5-turbo-instruct", max_tokens=num_outputs)
10
-
11
-
12
 
13
  os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
14
 
15
-
16
  def construct_index(directory_path):
17
- max_input_size = 4096
18
- num_outputs = 512
19
- max_chunk_overlap = 20
20
- chunk_size_limit = 600
21
-
22
- prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
23
-
24
- llm_predictor = LLMPredictor(llm=llm)
25
-
26
- documents = SimpleDirectoryReader(directory_path).load_data()
27
-
28
- index = GPTSimpleVectorIndex(documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper)
29
-
30
- index.save_to_disk('index.json')
31
 
32
- return index
33
-
34
  def chatbot(input_text):
35
- predetermined_text = "- please only answer using information found in the directory 'docs' and nothing else"
36
- input_text = input_text + predetermined_text
37
- index = GPTSimpleVectorIndex.load_from_disk('index.json')
38
- response = index.query(input_text, response_mode="compact")
39
- return response.response
 
40
 
41
  iface = gr.Interface(fn=chatbot,
42
- inputs=gr.components.Textbox(lines=7, label="What do you want to know about the project?"),
43
  outputs="text",
44
- title="Project Knowledge AI")
45
 
46
- index = construct_index("docs")
47
- iface.launch()
 
1
+ import openai
 
 
2
  import gradio as gr
 
 
3
  import sys
4
+ import os
 
 
 
5
 
6
  os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
7
 
 
8
  def construct_index(directory_path):
9
+ # Your existing code for index construction remains unchanged
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
 
 
11
  def chatbot(input_text):
12
+ response = openai.Completion.create(
13
+ model="text-davinci-003", # Specify the GPT-3 model you want to use
14
+ prompt=input_text,
15
+ max_tokens=150 # Adjust the max tokens based on your requirements
16
+ )
17
+ return response.choices[0].text.strip()
18
 
19
  iface = gr.Interface(fn=chatbot,
20
+ inputs=gr.inputs.Textbox(lines=7, label="Enter your text"),
21
  outputs="text",
22
+ title="Custom-trained AI Chatbot")
23
 
24
+ # index = construct_index("docs") # You may not need this line anymore
25
+ iface.launch(share=True)