Spaces:
Runtime error
Runtime error
Commit
·
37f029a
1
Parent(s):
03efeac
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,6 @@ import re
|
|
| 6 |
import requests
|
| 7 |
import os
|
| 8 |
import shutil
|
| 9 |
-
import gofile
|
| 10 |
import json
|
| 11 |
import time
|
| 12 |
|
|
@@ -19,20 +18,15 @@ def download_local(url):
|
|
| 19 |
resp = requests.get(url, allow_redirects=True)
|
| 20 |
filename, file_extension = os.path.splitext(url)
|
| 21 |
filename = os.path.basename(url)
|
| 22 |
-
|
| 23 |
-
filename = filename+'.jpg'
|
| 24 |
-
|
| 25 |
-
filename = 'images/{}_{}'.format(int(time.time()), filename)
|
| 26 |
with open(filename, 'wb') as handler:
|
| 27 |
handler.write(resp.content)
|
| 28 |
return filename
|
| 29 |
|
| 30 |
|
| 31 |
-
def download(text
|
| 32 |
pattern = '(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-&?=%.]+'
|
| 33 |
print(text)
|
| 34 |
-
print('upload?: ',is_upload)
|
| 35 |
-
|
| 36 |
urls = re.findall(pattern, text)
|
| 37 |
print(f'{len(urls)} urls')
|
| 38 |
|
|
@@ -52,19 +46,15 @@ def download(text, is_upload):
|
|
| 52 |
err_msgs.append(f'error downloading: {url} - {str(e)}')
|
| 53 |
|
| 54 |
#zipping
|
| 55 |
-
print('zipping
|
| 56 |
-
shutil.make_archive('images', 'zip'
|
| 57 |
|
| 58 |
result = '{} link found, {}'.format(len(urls), " ,\n ".join(err_msgs))
|
| 59 |
|
| 60 |
-
if is_upload == 'yes':
|
| 61 |
-
print('uploading...')
|
| 62 |
-
download_links = gofile.Gofile().upload(["images.zip"])
|
| 63 |
-
result += f'download link : {" ".join(download_links)}'
|
| 64 |
|
| 65 |
return "images.zip", result
|
| 66 |
|
| 67 |
iface = gr.Interface(fn=download,
|
| 68 |
-
inputs=["text"
|
| 69 |
outputs=["file", "text"])
|
| 70 |
iface.launch(debug=True)
|
|
|
|
| 6 |
import requests
|
| 7 |
import os
|
| 8 |
import shutil
|
|
|
|
| 9 |
import json
|
| 10 |
import time
|
| 11 |
|
|
|
|
| 18 |
resp = requests.get(url, allow_redirects=True)
|
| 19 |
filename, file_extension = os.path.splitext(url)
|
| 20 |
filename = os.path.basename(url)
|
| 21 |
+
#filename = 'images/{}_{}'.format(int(time.time()), filename)
|
|
|
|
|
|
|
|
|
|
| 22 |
with open(filename, 'wb') as handler:
|
| 23 |
handler.write(resp.content)
|
| 24 |
return filename
|
| 25 |
|
| 26 |
|
| 27 |
+
def download(text):
|
| 28 |
pattern = '(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-&?=%.]+'
|
| 29 |
print(text)
|
|
|
|
|
|
|
| 30 |
urls = re.findall(pattern, text)
|
| 31 |
print(f'{len(urls)} urls')
|
| 32 |
|
|
|
|
| 46 |
err_msgs.append(f'error downloading: {url} - {str(e)}')
|
| 47 |
|
| 48 |
#zipping
|
| 49 |
+
print('zipping ...')
|
| 50 |
+
shutil.make_archive('images', 'zip')
|
| 51 |
|
| 52 |
result = '{} link found, {}'.format(len(urls), " ,\n ".join(err_msgs))
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
return "images.zip", result
|
| 56 |
|
| 57 |
iface = gr.Interface(fn=download,
|
| 58 |
+
inputs=["text"],
|
| 59 |
outputs=["file", "text"])
|
| 60 |
iface.launch(debug=True)
|