acecalisto3 commited on
Commit
7203d3a
·
verified ·
1 Parent(s): 3244846

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -78
app.py CHANGED
@@ -98,7 +98,7 @@ class URLProcessor:
98
  return None
99
 
100
  direct_url = f"https://drive.google.com/uc?export=download&id={file_id.group(1)}"
101
- response = self.session.get(direct_url, timeout=self.timeout)
102
  response.raise_for_status()
103
 
104
  return {
@@ -156,15 +156,6 @@ class FileProcessor:
156
  self.max_file_size = max_file_size
157
  self.supported_text_extensions = {'.txt', '.md', '.csv', '.json', '.xml'}
158
 
159
- def is_text_file(self, filepath: str) -> bool:
160
- """Check if file is a text file"""
161
- try:
162
- mime_type, _ = mimetypes.guess_type(filepath)
163
- return (mime_type and mime_type.startswith('text/')) or \
164
- (os.path.splitext(filepath)[1].lower() in self.supported_text_extensions)
165
- except Exception:
166
- return False
167
-
168
  def process_file(self, file) -> List[Dict]:
169
  """Process uploaded file with enhanced error handling"""
170
  if not file:
@@ -232,32 +223,6 @@ class FileProcessor:
232
  logger.error(f"File processing error: {e}")
233
  return []
234
 
235
- class Chatbot:
236
- """Simple chatbot that uses provided JSON data for responses."""
237
-
238
- def __init__(self):
239
- self.data = None
240
-
241
- def load_data(self, json_data: str):
242
- """Load JSON data into the chatbot."""
243
- try:
244
- self.data = json.loads(json_data)
245
- return "Data loaded successfully!"
246
- except json.JSONDecodeError:
247
- return "Invalid JSON data. Please check your input."
248
-
249
- def chat(self, user_input: str) -> str:
250
- """Generate a response based on user input and loaded data."""
251
- if not self.data:
252
- return "No data loaded. Please load your JSON data first."
253
-
254
- # Simple keyword-based response logic
255
- for key, value in self.data.items():
256
- if key.lower() in user_input.lower():
257
- return f"{key}: {value}"
258
-
259
- return "I don't have information on that. Please ask about something else."
260
-
261
  def create_interface():
262
  """Create a comprehensive Gradio interface with advanced features"""
263
 
@@ -290,27 +255,11 @@ def create_interface():
290
  placeholder="Paste your text here..."
291
  )
292
 
293
- with gr.Tab("Chat"):
294
- chat_input = gr.Textbox(
295
- label="Chat with your data",
296
- placeholder="Type your question here..."
297
- )
298
- json_input = gr.Textbox(
299
- label="Load JSON Data",
300
- placeholder="Paste your JSON data here...",
301
- lines=5
302
- )
303
- load_btn = gr.Button("Load Data")
304
- chat_output = gr.Textbox(label="Chatbot Response", interactive=False)
305
-
306
  process_btn = gr.Button("Process Input", variant="primary")
307
 
308
  output_text = gr.Textbox(label="Processing Results", interactive=False)
309
  output_file = gr.File(label="Processed Output")
310
 
311
- # Initialize chatbot
312
- chatbot = Chatbot()
313
-
314
  def process_all_inputs(urls, file, text):
315
  """Process all input types with progress tracking"""
316
  try:
@@ -365,39 +314,18 @@ def create_interface():
365
  except Exception as e:
366
  logger.error(f"Processing error: {e}")
367
  return None, f"Error: {str(e)}"
368
-
369
- def load_chat_data(json_data):
370
- """Load JSON data into the chatbot."""
371
- return chatbot.load_data(json_data)
372
-
373
- def chat_with_data(user_input):
374
- """Chat with the loaded data."""
375
- return chatbot.chat(user_input)
376
-
377
  process_btn.click(
378
  process_all_inputs,
379
  inputs=[url_input, file_input, text_input],
380
  outputs=[output_file, output_text]
381
  )
382
-
383
- load_btn.click(
384
- load_chat_data,
385
- inputs=json_input,
386
- outputs=chat_output
387
- )
388
-
389
- chat_input.submit(
390
- chat_with_data,
391
- inputs=chat_input,
392
- outputs=chat_output
393
- )
394
 
395
  gr.Markdown("""
396
  ### Usage Guidelines
397
  - **URL Processing**: Enter valid HTTP/HTTPS URLs
398
  - **File Input**: Upload text files or ZIP archives
399
  - **Text Input**: Direct text processing
400
- - **Chat**: Load your JSON data and ask questions about it
401
  - Advanced cleaning and validation included
402
  """)
403
 
@@ -414,10 +342,10 @@ def main():
414
  interface.launch(
415
  server_name="0.0.0.0",
416
  server_port=7860,
417
- share=True, # Enable public sharing
418
- inbrowser=False,
419
- debug=False
420
  )
421
 
422
  if __name__ == "__main__":
423
- main()
 
98
  return None
99
 
100
  direct_url = f"https://drive.google.com/uc?export=download&id={file_id.group(1)}"
101
+ response = self.session.get(direct_url, timeout = self.timeout)
102
  response.raise_for_status()
103
 
104
  return {
 
156
  self.max_file_size = max_file_size
157
  self.supported_text_extensions = {'.txt', '.md', '.csv', '.json', '.xml'}
158
 
 
 
 
 
 
 
 
 
 
159
  def process_file(self, file) -> List[Dict]:
160
  """Process uploaded file with enhanced error handling"""
161
  if not file:
 
223
  logger.error(f"File processing error: {e}")
224
  return []
225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  def create_interface():
227
  """Create a comprehensive Gradio interface with advanced features"""
228
 
 
255
  placeholder="Paste your text here..."
256
  )
257
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  process_btn = gr.Button("Process Input", variant="primary")
259
 
260
  output_text = gr.Textbox(label="Processing Results", interactive=False)
261
  output_file = gr.File(label="Processed Output")
262
 
 
 
 
263
  def process_all_inputs(urls, file, text):
264
  """Process all input types with progress tracking"""
265
  try:
 
314
  except Exception as e:
315
  logger.error(f"Processing error: {e}")
316
  return None, f"Error: {str(e)}"
317
+
 
 
 
 
 
 
 
 
318
  process_btn.click(
319
  process_all_inputs,
320
  inputs=[url_input, file_input, text_input],
321
  outputs=[output_file, output_text]
322
  )
 
 
 
 
 
 
 
 
 
 
 
 
323
 
324
  gr.Markdown("""
325
  ### Usage Guidelines
326
  - **URL Processing**: Enter valid HTTP/HTTPS URLs
327
  - **File Input**: Upload text files or ZIP archives
328
  - **Text Input**: Direct text processing
 
329
  - Advanced cleaning and validation included
330
  """)
331
 
 
342
  interface.launch(
343
  server_name="0.0.0.0",
344
  server_port=7860,
345
+ share=False,
346
+ inbrowser=False, # Disable browser opening in container
347
+ debug=False # Disable debug mode for production
348
  )
349
 
350
  if __name__ == "__main__":
351
+ main()