Stereo0001 commited on
Commit
c4f92b6
·
1 Parent(s): bd02505

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -9,7 +9,7 @@ import gradio as gr
9
  import requests
10
  import os
11
  import shutil
12
-
13
  try: os.mkdir('images')
14
  except: print('images dir might already exist...')
15
 
@@ -17,13 +17,14 @@ except: print('images dir might already exist...')
17
  def download_local(url):
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
- print(filename)
23
  with open(filename, 'wb') as handler:
24
  for chunk in resp.iter_content(chunk_size = 1024): # 1024 bytes
25
  if chunk:
26
  handler.write(chunk)
 
27
  return filename
28
 
29
 
@@ -32,7 +33,7 @@ def download(text):
32
  #print(text)
33
  urls = re.findall(pattern, text)
34
  print(f'{len(urls)} urls')
35
- print(urls)
36
 
37
  if len(urls) == 0 :
38
  return 'No Url Found'
@@ -53,10 +54,10 @@ def download(text):
53
 
54
  result = '{} link found, {}'.format(len(urls), " ,\n ".join(err_msgs))
55
 
56
-
57
  return "images.zip", result
58
 
59
  iface = gr.Interface(fn=download,
60
  inputs=["text"],
61
- outputs=["file", "text"])
62
- iface.launch()
 
9
  import requests
10
  import os
11
  import shutil
12
+ import time
13
  try: os.mkdir('images')
14
  except: print('images dir might already exist...')
15
 
 
17
  def download_local(url):
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
+ print('文件名字:',filename)
23
  with open(filename, 'wb') as handler:
24
  for chunk in resp.iter_content(chunk_size = 1024): # 1024 bytes
25
  if chunk:
26
  handler.write(chunk)
27
+ print('下载完毕!',filename)
28
  return filename
29
 
30
 
 
33
  #print(text)
34
  urls = re.findall(pattern, text)
35
  print(f'{len(urls)} urls')
36
+ print('转换后的网址:',urls)
37
 
38
  if len(urls) == 0 :
39
  return 'No Url Found'
 
54
 
55
  result = '{} link found, {}'.format(len(urls), " ,\n ".join(err_msgs))
56
 
57
+ #返回压缩好的文件夹名字,后面规定好是文件即可,还返回了一部分文字信息
58
  return "images.zip", result
59
 
60
  iface = gr.Interface(fn=download,
61
  inputs=["text"],
62
+ outputs=["file", "text"])
63
+ iface.launch(share=True)