Spaces:
Runtime error
Runtime error
Commit
·
4acd628
1
Parent(s):
dc483b5
few updates
Browse files
app.py
CHANGED
@@ -23,7 +23,9 @@ user_api = {}
|
|
23 |
|
24 |
def set_apikey(state, api_key):
|
25 |
|
26 |
-
if
|
|
|
|
|
27 |
user_api[state] = api_key
|
28 |
|
29 |
return disable_box
|
@@ -84,17 +86,18 @@ class my_app:
|
|
84 |
|
85 |
|
86 |
def get_response(state, history, query, file):
|
87 |
-
|
|
|
88 |
if not file:
|
89 |
raise gr.Error(message='Upload a PDF')
|
90 |
-
|
|
|
91 |
app = my_app()
|
92 |
user_app[state] = app
|
93 |
else:
|
94 |
app = user_app[state]
|
95 |
|
96 |
-
app.OPENAI_API_KEY = user_api[state]
|
97 |
-
|
98 |
chain = app(file)
|
99 |
|
100 |
result = chain({"question": query, 'chat_history':app.chat_history},return_only_outputs=True)
|
@@ -106,11 +109,9 @@ def get_response(state, history, query, file):
|
|
106 |
yield history,''
|
107 |
|
108 |
def render_file(state,file):
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
else:
|
113 |
-
app = user_app[state]
|
114 |
doc = fitz.open(file.name)
|
115 |
page = doc[app.N]
|
116 |
#Render the page as a PNG image with a resolution of 300 DPI
|
|
|
23 |
|
24 |
def set_apikey(state, api_key):
|
25 |
|
26 |
+
if not user_app:
|
27 |
+
user_api[state] = api_key
|
28 |
+
elif state != list(user_app.keys())[-1]:
|
29 |
user_api[state] = api_key
|
30 |
|
31 |
return disable_box
|
|
|
86 |
|
87 |
|
88 |
def get_response(state, history, query, file):
|
89 |
+
global user_app, user_api
|
90 |
+
print(user_app, user_api, state)
|
91 |
if not file:
|
92 |
raise gr.Error(message='Upload a PDF')
|
93 |
+
|
94 |
+
if not user_app or state != list(user_app.keys())[-1]:
|
95 |
app = my_app()
|
96 |
user_app[state] = app
|
97 |
else:
|
98 |
app = user_app[state]
|
99 |
|
100 |
+
app.OPENAI_API_KEY = user_api[state]
|
|
|
101 |
chain = app(file)
|
102 |
|
103 |
result = chain({"question": query, 'chat_history':app.chat_history},return_only_outputs=True)
|
|
|
109 |
yield history,''
|
110 |
|
111 |
def render_file(state,file):
|
112 |
+
|
113 |
+
app = user_app[state]
|
114 |
+
|
|
|
|
|
115 |
doc = fitz.open(file.name)
|
116 |
page = doc[app.N]
|
117 |
#Render the page as a PNG image with a resolution of 300 DPI
|