Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -472,31 +472,32 @@ class DataHandler:
|
|
| 472 |
|
| 473 |
@staticmethod
|
| 474 |
@handle_errors(default_return="")
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
|
|
|
| 500 |
|
| 501 |
# Main Application
|
| 502 |
class SentimentApp:
|
|
|
|
| 472 |
|
| 473 |
@staticmethod
|
| 474 |
@handle_errors(default_return="")
|
| 475 |
+
def process_file(file) -> str:
|
| 476 |
+
"""Process uploaded file"""
|
| 477 |
+
if not file:
|
| 478 |
+
return ""
|
| 479 |
+
|
| 480 |
+
content = file.read().decode('utf-8')
|
| 481 |
+
|
| 482 |
+
if file.name.endswith('.csv'):
|
| 483 |
+
import io
|
| 484 |
+
csv_file = io.StringIO(content)
|
| 485 |
+
reader = csv.reader(csv_file)
|
| 486 |
+
try:
|
| 487 |
+
headers = next(reader)
|
| 488 |
+
text_idx = next((i for i, h in enumerate(headers) if h.strip().lower() == 'text'), 0)
|
| 489 |
+
texts = []
|
| 490 |
+
for row in reader:
|
| 491 |
+
if len(row) > text_idx and row[text_idx].strip():
|
| 492 |
+
text = row[text_idx].strip().strip('"')
|
| 493 |
+
texts.append(text)
|
| 494 |
+
return '\n'.join(texts)
|
| 495 |
+
except Exception as e:
|
| 496 |
+
lines = content.strip().split('\n')[1:]
|
| 497 |
+
return '\n'.join(line.strip().strip('"') for line in lines if line.strip())
|
| 498 |
+
|
| 499 |
+
return content
|
| 500 |
+
|
| 501 |
|
| 502 |
# Main Application
|
| 503 |
class SentimentApp:
|