Spaces:
Sleeping
Sleeping
Update other_function.py
Browse files- other_function.py +4 -21
other_function.py
CHANGED
|
@@ -154,6 +154,7 @@ def get_news():
|
|
| 154 |
|
| 155 |
|
| 156 |
def download_and_save_as_txt(url, account_sid, auth_token):
|
|
|
|
| 157 |
try:
|
| 158 |
# Make the request to the media URL with authentication
|
| 159 |
response = requests.get(url, auth=HTTPBasicAuth(account_sid, auth_token))
|
|
@@ -170,31 +171,13 @@ def download_and_save_as_txt(url, account_sid, auth_token):
|
|
| 170 |
file.write(response.content)
|
| 171 |
|
| 172 |
print(f"Media downloaded successfully and saved as {txt_filepath}")
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
except requests.exceptions.HTTPError as err:
|
| 176 |
-
print(f"HTTP error occurred: {err}")
|
| 177 |
-
except Exception as err:
|
| 178 |
-
print(f"An error occurred: {err}")
|
| 179 |
-
|
| 180 |
-
def download_file(url, extension):
|
| 181 |
-
try:
|
| 182 |
-
response = requests.get(url)
|
| 183 |
-
response.raise_for_status()
|
| 184 |
-
filename = f"{uuid.uuid4()}{extension}"
|
| 185 |
-
file_path = os.path.join(UPLOAD_FOLDER, filename)
|
| 186 |
-
|
| 187 |
-
with open(file_path, 'wb') as file:
|
| 188 |
-
file.write(response.content)
|
| 189 |
-
|
| 190 |
-
print(f"File downloaded and saved as {file_path}")
|
| 191 |
-
return file_path
|
| 192 |
|
| 193 |
except requests.exceptions.HTTPError as err:
|
| 194 |
print(f"HTTP error occurred: {err}")
|
| 195 |
except Exception as err:
|
| 196 |
print(f"An error occurred: {err}")
|
| 197 |
-
return None
|
| 198 |
|
| 199 |
|
| 200 |
def extract_text_from_pdf(pdf_path):
|
|
@@ -208,7 +191,7 @@ def extract_text_from_pdf(pdf_path):
|
|
| 208 |
return pdf_text
|
| 209 |
|
| 210 |
|
| 211 |
-
def respond_pdf(
|
| 212 |
if
|
| 213 |
res = ''
|
| 214 |
for chunk in AI71(AI71_API_KEY).chat.completions.create(
|
|
|
|
| 154 |
|
| 155 |
|
| 156 |
def download_and_save_as_txt(url, account_sid, auth_token):
|
| 157 |
+
global pdf_text
|
| 158 |
try:
|
| 159 |
# Make the request to the media URL with authentication
|
| 160 |
response = requests.get(url, auth=HTTPBasicAuth(account_sid, auth_token))
|
|
|
|
| 171 |
file.write(response.content)
|
| 172 |
|
| 173 |
print(f"Media downloaded successfully and saved as {txt_filepath}")
|
| 174 |
+
pdf_text=extract_text_from_pdf(txt_filepath)
|
| 175 |
+
return txt_filepath
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
except requests.exceptions.HTTPError as err:
|
| 178 |
print(f"HTTP error occurred: {err}")
|
| 179 |
except Exception as err:
|
| 180 |
print(f"An error occurred: {err}")
|
|
|
|
| 181 |
|
| 182 |
|
| 183 |
def extract_text_from_pdf(pdf_path):
|
|
|
|
| 191 |
return pdf_text
|
| 192 |
|
| 193 |
|
| 194 |
+
def respond_pdf(pdf_text=pdf_text,query):
|
| 195 |
if
|
| 196 |
res = ''
|
| 197 |
for chunk in AI71(AI71_API_KEY).chat.completions.create(
|