Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,26 +8,33 @@ import sys
|
|
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,
|
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 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
|
32 |
-
|
33 |
-
chatbot_interface("") # start interface with empty api key as default value
|
|
|
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,api):
|
|
|
29 |
index = GPTSimpleVectorIndex.load_from_disk('index.json')
|
30 |
response = index.query(question, response_mode="compact")
|
31 |
return response.response
|
32 |
|
33 |
+
os.environ["OPENAI_API_KEY"] = "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"
|
34 |
|
35 |
+
construct_index("data")
|
36 |
+
api_key = gr.inputs.Textbox(label="OpenAI API Key")
|
37 |
+
iface = gr.Interface(fn=ask_ai, inputs=["text", api_key], outputs="text", title="Chatbot")
|
38 |
|
39 |
|
40 |
+
iface.launch()
|
|