Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,35 +8,26 @@ import sys
|
|
8 |
from IPython.display import Markdown, display
|
9 |
|
10 |
|
11 |
-
|
12 |
-
|
13 |
def construct_index(directory_path):
|
14 |
-
|
15 |
max_input_size = 4096
|
16 |
-
|
17 |
num_outputs = 2000
|
18 |
-
|
19 |
max_chunk_overlap = 20
|
20 |
-
|
21 |
chunk_size_limit = 600
|
22 |
-
|
23 |
-
|
24 |
llm_predictor = LLMPredictor(llm=OpenAI(temperature=0.5, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
|
25 |
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
|
26 |
|
27 |
-
|
28 |
-
def ask_ai(question,
|
|
|
29 |
index = GPTSimpleVectorIndex.load_from_disk('index.json')
|
30 |
response = index.query(question, response_mode="compact")
|
31 |
return response.response
|
32 |
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
iface.launch()
|
|
|
8 |
from IPython.display import Markdown, display
|
9 |
|
10 |
|
|
|
|
|
11 |
def construct_index(directory_path):
|
|
|
12 |
max_input_size = 4096
|
|
|
13 |
num_outputs = 2000
|
|
|
14 |
max_chunk_overlap = 20
|
|
|
15 |
chunk_size_limit = 600
|
|
|
|
|
16 |
llm_predictor = LLMPredictor(llm=OpenAI(temperature=0.5, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
|
17 |
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
|
18 |
|
19 |
+
|
20 |
+
def ask_ai(question, api_key):
|
21 |
+
os.environ["OPENAI_API_KEY"] = api_key
|
22 |
index = GPTSimpleVectorIndex.load_from_disk('index.json')
|
23 |
response = index.query(question, response_mode="compact")
|
24 |
return response.response
|
25 |
|
26 |
|
27 |
+
def chatbot_interface(api_key):
|
28 |
+
iface = gr.Interface(fn=ask_ai, inputs=["text", gr.inputs.Textbox(label="OpenAI API Key")], outputs="text", title="Chatbot")
|
29 |
+
iface.launch()
|
30 |
|
31 |
|
32 |
+
construct_index("data")
|
33 |
+
chatbot_interface("") # start interface with empty api key as default value
|
|
|
|