Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,15 @@
|
|
1 |
import gradio as gr
|
2 |
import json
|
|
|
3 |
from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
|
4 |
from langchain import OpenAI
|
5 |
import sys
|
6 |
-
|
7 |
from IPython.display import Markdown, display
|
8 |
|
|
|
|
|
|
|
9 |
def construct_index(directory_path):
|
10 |
|
11 |
max_input_size = 4096
|
@@ -20,18 +24,30 @@ def construct_index(directory_path):
|
|
20 |
llm_predictor = LLMPredictor(llm=OpenAI(temperature=0.5, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
|
21 |
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
|
22 |
|
23 |
-
|
24 |
-
def ask_ai(question,
|
25 |
-
if api_key == "":
|
26 |
-
api_key = "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"
|
27 |
-
os.environ["OPENAI_API_KEY"] = api_key
|
28 |
index = GPTSimpleVectorIndex.load_from_disk('index.json')
|
29 |
response = index.query(question, response_mode="compact")
|
30 |
return response.response
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
construct_index("data")
|
34 |
|
35 |
-
iface = gr.Interface(fn=ask_ai, inputs=["text", "text"] ,outputs="text", title="Jim's Chatbot")
|
36 |
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
+
import os
|
4 |
from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
|
5 |
from langchain import OpenAI
|
6 |
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
|
|
|
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 |
+
|
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="text", outputs="text" ,title="Chatbot")
|
51 |
+
|
52 |
+
|
53 |
+
iface.launch()
|