Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,47 +7,30 @@ import sys
|
|
7 |
|
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 |
-
os.environ["OPENAI_API_KEY"] = "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"
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
construct_index("data")
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
50 |
-
iface = gr.Interface(fn=ask_ai, inputs=
|
51 |
-
|
52 |
|
53 |
-
iface.launch()
|
|
|
7 |
|
8 |
from IPython.display import Markdown, display
|
9 |
|
|
|
|
|
|
|
10 |
def construct_index(directory_path):
|
11 |
|
12 |
max_input_size = 4096
|
|
|
13 |
num_outputs = 2000
|
|
|
14 |
max_chunk_overlap = 20
|
|
|
15 |
chunk_size_limit = 600
|
16 |
|
|
|
17 |
llm_predictor = LLMPredictor(llm=OpenAI(temperature=0.5, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
|
18 |
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
|
|
|
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 |
construct_index("data")
|
27 |
|
28 |
+
api_key_input = gr.inputs.Textbox(label="Enter your OpenAI API Key")
|
29 |
|
30 |
+
question_input = gr.inputs.Textbox(label="Ask a question")
|
31 |
|
32 |
+
output_text = gr.outputs.Textbox(label="Answer")
|
33 |
|
34 |
+
iface = gr.Interface(fn=ask_ai, inputs=[question_input, api_key_input], outputs=output_text, title="OpenAI Chatbot")
|
|
|
35 |
|
36 |
+
iface.launch()
|