Spaces:
Sleeping
Sleeping
Commit
·
0aba4f3
1
Parent(s):
6a44c37
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,10 @@ import openai
|
|
| 7 |
import gradio as gr
|
| 8 |
import os
|
| 9 |
from sklearn.neighbors import NearestNeighbors
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def download_pdf(url, output_path):
|
| 12 |
urllib.request.urlretrieve(url, output_path)
|
|
@@ -131,6 +135,7 @@ def generate_answer(question,openAI_key):
|
|
| 131 |
return answer
|
| 132 |
|
| 133 |
|
|
|
|
| 134 |
def question_answer(url, file, question,openAI_key):
|
| 135 |
if openAI_key.strip()=='':
|
| 136 |
return '[ERROR]: Please enter you Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
|
|
@@ -156,6 +161,22 @@ def question_answer(url, file, question,openAI_key):
|
|
| 156 |
return '[ERROR]: Question field is empty'
|
| 157 |
|
| 158 |
return generate_answer(question,openAI_key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
|
| 161 |
recommender = SemanticSearch()
|
|
|
|
| 7 |
import gradio as gr
|
| 8 |
import os
|
| 9 |
from sklearn.neighbors import NearestNeighbors
|
| 10 |
+
from datasets import load_dataset
|
| 11 |
+
|
| 12 |
+
dataset = load_dataset('text', data_files='path_to_your_directory/*.txt')
|
| 13 |
+
|
| 14 |
|
| 15 |
def download_pdf(url, output_path):
|
| 16 |
urllib.request.urlretrieve(url, output_path)
|
|
|
|
| 135 |
return answer
|
| 136 |
|
| 137 |
|
| 138 |
+
'''
|
| 139 |
def question_answer(url, file, question,openAI_key):
|
| 140 |
if openAI_key.strip()=='':
|
| 141 |
return '[ERROR]: Please enter you Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
|
|
|
|
| 161 |
return '[ERROR]: Question field is empty'
|
| 162 |
|
| 163 |
return generate_answer(question,openAI_key)
|
| 164 |
+
'''
|
| 165 |
+
|
| 166 |
+
# New code for single staticPDF
|
| 167 |
+
def question_answer(question, openAI_key):
|
| 168 |
+
# Check for empty OpenAI key or question
|
| 169 |
+
if openAI_key.strip() == '':
|
| 170 |
+
return '[ERROR]: Please enter you Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
|
| 171 |
+
if question.strip() == '':
|
| 172 |
+
return '[ERROR]: Question field is empty'
|
| 173 |
+
|
| 174 |
+
# URL of your PDF
|
| 175 |
+
url = 'https://huggingface.co/datasets/maconphillips/Warren-VT-Info/resolve/main/town-plan.pdf'
|
| 176 |
+
download_pdf(url, 'corpus.pdf')
|
| 177 |
+
load_recommender('corpus.pdf')
|
| 178 |
+
|
| 179 |
+
return generate_answer(question, openAI_key)
|
| 180 |
|
| 181 |
|
| 182 |
recommender = SemanticSearch()
|