Omnibus commited on
Commit
a6637aa
·
1 Parent(s): 2192ac7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -13
app.py CHANGED
@@ -154,24 +154,25 @@ def compress_data(c, instruct, history):
154
 
155
 
156
 
157
- def summarize(inp,history,data=None,file=None):
158
  if inp == "":
159
  inp = "Summarize this data"
160
 
161
 
162
  history = [(inp,"Working on it...")]
163
  yield "",history
164
- if file:
165
  try:
166
- print (file)
167
- if file.endswith(".pdf"):
168
- zz=read_pdf(file)
169
- print (zz)
170
- data=f'{data}\nFile:\n{zz}'
171
- elif file.endswith(".txt"):
172
- zz=read_txt(file)
173
- print (zz)
174
- data=f'{data}\nFile:\n{zz}'
 
175
  except Exception as e:
176
  data = "Error"
177
  print (e)
@@ -216,10 +217,10 @@ with gr.Blocks() as app:
216
  clear_btn = gr.Button("Clear")
217
  with gr.Row():
218
  data=gr.Textbox(label="Input Data (paste text)", lines=6)
219
- file=gr.File(label="Input File (.pdf .txt)")
220
  #text=gr.JSON()
221
  #inp_query.change(search_models,inp_query,models_dd)
222
  clear_btn.click(clear_fn,None,[prompt,chatbot])
223
  go=button.click(summarize,[prompt,chatbot,data,file],[prompt,chatbot],concurrency_limit=1)
224
  stop_button.click(None,None,None,cancels=[go])
225
- app.launch(server_port=7860,show_api=False)
 
154
 
155
 
156
 
157
+ def summarize(inp,history,data=None,files=None):
158
  if inp == "":
159
  inp = "Summarize this data"
160
 
161
 
162
  history = [(inp,"Working on it...")]
163
  yield "",history
164
+ if files:
165
  try:
166
+ for i, file in enumerate(files):
167
+ print (file)
168
+ if file.endswith(".pdf"):
169
+ zz=read_pdf(file)
170
+ print (zz)
171
+ data=f'{data}\nFile Name ({file}):\n{zz}'
172
+ elif file.endswith(".txt"):
173
+ zz=read_txt(file)
174
+ print (zz)
175
+ data=f'{data}\nFile Name ({file}):\n{zz}'
176
  except Exception as e:
177
  data = "Error"
178
  print (e)
 
217
  clear_btn = gr.Button("Clear")
218
  with gr.Row():
219
  data=gr.Textbox(label="Input Data (paste text)", lines=6)
220
+ file=gr.Files(label="Input File(s) (.pdf .txt)")
221
  #text=gr.JSON()
222
  #inp_query.change(search_models,inp_query,models_dd)
223
  clear_btn.click(clear_fn,None,[prompt,chatbot])
224
  go=button.click(summarize,[prompt,chatbot,data,file],[prompt,chatbot],concurrency_limit=1)
225
  stop_button.click(None,None,None,cancels=[go])
226
+ app.launch(server_port=7860,show_api=False)