acecalisto3 commited on
Commit
8b83f9c
Β·
verified Β·
1 Parent(s): 92bd1ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -32,7 +32,7 @@ class URLProcessor:
32
  self.session = requests.Session()
33
  self.timeout = 10 # seconds
34
  self.session.headers.update({
35
- 'User -Agent': UserAgent().random,
36
  'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
37
  'Accept-Language': 'en-US,en;q=0.5',
38
  'Accept-Encoding': 'gzip, deflate, br',
@@ -94,7 +94,7 @@ class URLProcessor:
94
  try:
95
  file_id = re.search(r'/file/d/([a-zA-Z0-9_-]+)', url)
96
  if not file_id:
97
- logger.error(f"Invalid Google Drive URL: {url}")
98
  return None
99
 
100
  direct_url = f"https://drive.google.com/uc?export=download&id={file_id.group(1)}"
@@ -115,7 +115,7 @@ class URLProcessor:
115
  try:
116
  response = self.session.get(url, timeout=self.timeout)
117
  response.raise_for_status()
118
- return {
119
  'content': response.text,
120
  'content_type': 'text/calendar',
121
  'timestamp': datetime.now().isoformat()
@@ -223,7 +223,7 @@ class FileProcessor:
223
  'source': 'file',
224
  'filename': os.path.basename(file.name),
225
  'file_size': file_stat.st_size,
226
- 'mime_type': mimetypes.guess_type(file.name)[0],
227
  'created': datetime.fromtimestamp(file_stat.st_ctime).isoformat(),
228
  'modified': datetime.fromtimestamp(file_stat.st_mtime).isoformat(),
229
  'content': content,
@@ -263,13 +263,18 @@ def create_interface():
263
  """Create a comprehensive Gradio interface with advanced features"""
264
 
265
  css = """
266
- .container { max-width: 1200px; margin: auto; }
267
- .warning { background-color: #fff3cd; color: #856404; }
268
- .error { background-color: #f8d7da; color: #721c24; }
 
 
 
 
 
269
  """
270
 
271
- with gr.Blocks(css=css, title="Advanced Text & URL Processor") as interface:
272
- gr.Markdown("# 🌐 Advanced URL & Text Processing Toolkit")
273
 
274
  with gr.Tab("URL Processing"):
275
  url_input = gr.Textbox(
@@ -301,7 +306,7 @@ def create_interface():
301
  placeholder="Paste your JSON data here...",
302
  lines=5
303
  )
304
- load_btn = gr.Button("Load Data")
305
  chat_output = gr.Textbox(label="Chatbot Response", interactive=False)
306
 
307
  process_btn = gr.Button("Process Input", variant="primary")
@@ -339,7 +344,7 @@ def create_interface():
339
  # Process files
340
  if files:
341
  combined_data = file_processor.process_files(files)
342
- results.extend(combined_data)
343
 
344
  # Process text input
345
  if text:
@@ -391,7 +396,7 @@ def create_interface():
391
  chat_input.submit(
392
  chat_with_data,
393
  inputs=chat_input,
394
- outputs= chat_output
395
  )
396
 
397
  gr.Markdown("""
 
32
  self.session = requests.Session()
33
  self.timeout = 10 # seconds
34
  self.session.headers.update({
35
+ 'User-Agent': UserAgent().random,
36
  'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
37
  'Accept-Language': 'en-US,en;q=0.5',
38
  'Accept-Encoding': 'gzip, deflate, br',
 
94
  try:
95
  file_id = re.search(r'/file/d/([a-zA-Z0-9_-]+)', url)
96
  if not file_id:
97
+ logger.error(f"Invalid Google Drive URL: { url}")
98
  return None
99
 
100
  direct_url = f"https://drive.google.com/uc?export=download&id={file_id.group(1)}"
 
115
  try:
116
  response = self.session.get(url, timeout=self.timeout)
117
  response.raise_for_status()
118
+ return {
119
  'content': response.text,
120
  'content_type': 'text/calendar',
121
  'timestamp': datetime.now().isoformat()
 
223
  'source': 'file',
224
  'filename': os.path.basename(file.name),
225
  'file_size': file_stat.st_size,
226
+ 'mime_type': mimetypes.guess_type(file.name)[0 ],
227
  'created': datetime.fromtimestamp(file_stat.st_ctime).isoformat(),
228
  'modified': datetime.fromtimestamp(file_stat.st_mtime).isoformat(),
229
  'content': content,
 
263
  """Create a comprehensive Gradio interface with advanced features"""
264
 
265
  css = """
266
+ body { background-color: #f0f4f8; font-family: 'Arial', sans-serif; }
267
+ .container { max-width: 1200px; margin: auto; padding: 20px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); }
268
+ h1 { color: #333; }
269
+ .tab { background-color: #ffffff; border-radius: 8px; padding: 20px; margin-bottom: 20px; }
270
+ .button { background-color: #007bff; color: white; border: none; border-radius: 5px; padding: 10px 20px; cursor: pointer; }
271
+ .button:hover { background-color: #0056b3; }
272
+ .warning { background-color: #fff3cd; color: #856404; padding: 10px; border-radius: 5px; }
273
+ .error { background-color: #f8d7da; color: #721c24; padding: 10px; border-radius: 5px; }
274
  """
275
 
276
+ with gr.Blocks(css=css, title="Advanced Data Processing App") as interface:
277
+ gr.Markdown("# 🌐 Advanced Data Processing Toolkit")
278
 
279
  with gr.Tab("URL Processing"):
280
  url_input = gr.Textbox(
 
306
  placeholder="Paste your JSON data here...",
307
  lines=5
308
  )
309
+ load_btn = gr.Button("Load Data", variant="primary")
310
  chat_output = gr.Textbox(label="Chatbot Response", interactive=False)
311
 
312
  process_btn = gr.Button("Process Input", variant="primary")
 
344
  # Process files
345
  if files:
346
  combined_data = file_processor.process_files(files)
347
+ results.extend (combined_data)
348
 
349
  # Process text input
350
  if text:
 
396
  chat_input.submit(
397
  chat_with_data,
398
  inputs=chat_input,
399
+ outputs=chat_output
400
  )
401
 
402
  gr.Markdown("""