Spaces:
Runtime error
Runtime error
Commit
·
ea50b28
1
Parent(s):
faecfdf
Update app.py
Browse files
app.py
CHANGED
@@ -98,18 +98,6 @@ def load_recommender(path, start_page=1):
|
|
98 |
recommender.fit(chunks)
|
99 |
return 'Corpus Loaded.'
|
100 |
|
101 |
-
def generate_text(openAI_key,prompt, engine="text-davinci-003"):
|
102 |
-
openai.api_key = openAI_key
|
103 |
-
completions = openai.Completion.create(
|
104 |
-
engine=engine,
|
105 |
-
prompt=prompt,
|
106 |
-
max_tokens=512,
|
107 |
-
n=1,
|
108 |
-
stop=None,
|
109 |
-
temperature=0.7,
|
110 |
-
)
|
111 |
-
message = completions.choices[0].text
|
112 |
-
return message
|
113 |
|
114 |
def generate_answer(question,openAI_key):
|
115 |
topn_chunks = recommender(question)
|
@@ -132,6 +120,31 @@ def generate_answer(question,openAI_key):
|
|
132 |
return answer
|
133 |
|
134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
def question_answer(url, file, question,openAI_key):
|
136 |
if openAI_key.strip()=='':
|
137 |
return '[ERROR]: Please enter you Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
|
|
|
98 |
recommender.fit(chunks)
|
99 |
return 'Corpus Loaded.'
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
def generate_answer(question,openAI_key):
|
103 |
topn_chunks = recommender(question)
|
|
|
120 |
return answer
|
121 |
|
122 |
|
123 |
+
def question_answer(url, file, question,openAI_key):
|
124 |
+
if openAI_key.strip()=='':
|
125 |
+
return '[ERROR]: Please enter you Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
|
126 |
+
if url.strip() == '' and file == None:
|
127 |
+
return '[ERROR]: Both URL and PDF is empty. Provide atleast one.'
|
128 |
+
|
129 |
+
if url.strip() != '' and file != None:
|
130 |
+
return '[ERROR]: Both URL and PDF is provided. Please provide only one (eiter URL or PDF).'
|
131 |
+
|
132 |
+
if url.strip() != '':
|
133 |
+
glob_url = url
|
134 |
+
download_pdf(glob_url, 'corpus.pdf')
|
135 |
+
load_recommender('corpus.pdf')
|
136 |
+
|
137 |
+
else:
|
138 |
+
old_file_name = file.name
|
139 |
+
file_name = file.name
|
140 |
+
file_name = file_name[:-12] + file_name[-4:]
|
141 |
+
os.rename(old_file_name, file_name)
|
142 |
+
load_recommender(file_name)
|
143 |
+
|
144 |
+
if question.strip() == '':
|
145 |
+
return '[ERROR]: Question field is empty'
|
146 |
+
|
147 |
+
return generate_answer(question,openAI_key)
|
148 |
def question_answer(url, file, question,openAI_key):
|
149 |
if openAI_key.strip()=='':
|
150 |
return '[ERROR]: Please enter you Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
|