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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -1,14 +1,14 @@
1
- from cProfile import label
2
- from distutils.log import debug
3
- from random import choices
4
- import gradio as gr
 
 
5
  import re
 
6
  import requests
7
  import os
8
  import shutil
9
- import json
10
- import time
11
-
12
 
13
  try: os.mkdir('images')
14
  except: print('images dir might already exist...')
@@ -21,7 +21,9 @@ def download_local(url):
21
  #filename = 'images/{}_{}'.format(int(time.time()), filename)
22
  print(filename)
23
  with open(filename, 'wb') as handler:
24
- handler.write(resp.content)
 
 
25
  return filename
26
 
27
 
@@ -47,7 +49,7 @@ def download(text):
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
 
@@ -57,4 +59,4 @@ def download(text):
57
  iface = gr.Interface(fn=download,
58
  inputs=["text"],
59
  outputs=["file", "text"])
60
- iface.launch(debug=True)
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Mon Jan 30 21:24:16 2023
4
+
5
+ @author: lizhenzhu
6
+ """
7
  import re
8
+ 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...')
 
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
 
 
49
 
50
  #zipping
51
  print('zipping ...')
52
+ shutil.make_archive('images', 'zip','images')
53
 
54
  result = '{} link found, {}'.format(len(urls), " ,\n ".join(err_msgs))
55
 
 
59
  iface = gr.Interface(fn=download,
60
  inputs=["text"],
61
  outputs=["file", "text"])
62
+ iface.launch()