Omnibus commited on
Commit
e37b210
·
1 Parent(s): 232ddba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -243,7 +243,7 @@ def compress_data(c, instruct, history):
243
 
244
 
245
 
246
- def summarize(inp,history,data=None,file=None,url=None,pdf_url=None):
247
  if inp == "":
248
  inp = "Process this data"
249
  history.clear()
@@ -260,20 +260,21 @@ def summarize(inp,history,data=None,file=None,url=None,pdf_url=None):
260
  rawp = str(out)
261
  else:
262
  data=out
263
- if file:
264
- try:
265
- print (file)
266
- if file.endswith(".pdf"):
267
- zz=read_pdf(file)
268
- print (zz)
269
- data=f'{data}\nFile:\n{zz}'
270
- elif file.endswith(".txt"):
271
- zz=read_txt(file)
272
- print (zz)
273
- data=f'{data}\nFile:\n{zz}'
274
- except Exception as e:
275
- data = "Error"
276
- print (e)
 
277
  if data != "Error" and data != "":
278
  print(inp)
279
  out = str(data)
@@ -317,7 +318,7 @@ with gr.Blocks() as app:
317
  with gr.Tab("Text"):
318
  data=gr.Textbox(label="Input Data (paste text)", lines=6)
319
  with gr.Tab("File"):
320
- file=gr.File(label="Input File (.pdf .txt)")
321
  with gr.Tab("URL"):
322
  url = gr.Textbox(label="URL")
323
  with gr.Tab("PDF URL"):
 
243
 
244
 
245
 
246
+ def summarize(inp,history,data=None,files=None,url=None,pdf_url=None):
247
  if inp == "":
248
  inp = "Process this data"
249
  history.clear()
 
260
  rawp = str(out)
261
  else:
262
  data=out
263
+ if files:
264
+ for i, file in enumerate(files):
265
+ try:
266
+ print (file)
267
+ if file.endswith(".pdf"):
268
+ zz=read_pdf(file)
269
+ print (zz)
270
+ data=f'{data}\nFile Name ({file}):\n{zz}'
271
+ elif file.endswith(".txt"):
272
+ zz=read_txt(file)
273
+ print (zz)
274
+ data=f'{data}\nFile Name ({file}):\n{zz}'
275
+ except Exception as e:
276
+ data=f'{data}\nError opening File Name ({file})'
277
+ print (e)
278
  if data != "Error" and data != "":
279
  print(inp)
280
  out = str(data)
 
318
  with gr.Tab("Text"):
319
  data=gr.Textbox(label="Input Data (paste text)", lines=6)
320
  with gr.Tab("File"):
321
+ file=gr.Files(label="Input File (.pdf .txt)")
322
  with gr.Tab("URL"):
323
  url = gr.Textbox(label="URL")
324
  with gr.Tab("PDF URL"):