Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,6 +12,7 @@ import gradio as gr
|
|
| 12 |
from huggingface_hub import hf_hub_download
|
| 13 |
import io
|
| 14 |
import matplotlib.pyplot as plt
|
|
|
|
| 15 |
|
| 16 |
# Device configuration: consistent device for model and tensors
|
| 17 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
|
@@ -221,14 +222,17 @@ def process_input(text_input, file):
|
|
| 221 |
comments = [p.strip() for p in parts if p and p.strip()]
|
| 222 |
|
| 223 |
elif file:
|
| 224 |
-
# Đọc file CSV hoặc TXT
|
| 225 |
-
|
| 226 |
if isinstance(file, str):
|
| 227 |
# file path
|
| 228 |
if file.lower().endswith('.csv'):
|
| 229 |
content = open(file, 'r', encoding='utf-8', errors='ignore').read()
|
| 230 |
lines = content.splitlines()
|
| 231 |
comments = [line.strip() for line in lines if line.strip()]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
else:
|
| 233 |
content = open(file, 'r', encoding='utf-8').read()
|
| 234 |
parts = re.split(r'[.?!]\s*|\n+', content)
|
|
@@ -283,7 +287,7 @@ with gr.Blocks() as demo:
|
|
| 283 |
gr.Markdown("Nhập bình luận:")
|
| 284 |
text_input = gr.Textbox(lines=6, placeholder="Nhập bình luận tại đây...", label="")
|
| 285 |
gr.Markdown("Hoặc tải lên tệp .txt hoặc .csv chứa các bình luận:")
|
| 286 |
-
file_input = gr.File(label="Tải tệp", file_types=[".txt", ".csv"])
|
| 287 |
predict_button = gr.Button("Dự đoán")
|
| 288 |
output_table = gr.Dataframe(headers=["Comment", "Dự đoán", 'Khả năng tiêu cực', 'Khả năng bình thường', 'Khả năng tích cực'],
|
| 289 |
interactive=False,
|
|
|
|
| 12 |
from huggingface_hub import hf_hub_download
|
| 13 |
import io
|
| 14 |
import matplotlib.pyplot as plt
|
| 15 |
+
from docx import Document
|
| 16 |
|
| 17 |
# Device configuration: consistent device for model and tensors
|
| 18 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
|
|
|
| 222 |
comments = [p.strip() for p in parts if p and p.strip()]
|
| 223 |
|
| 224 |
elif file:
|
|
|
|
|
|
|
| 225 |
if isinstance(file, str):
|
| 226 |
# file path
|
| 227 |
if file.lower().endswith('.csv'):
|
| 228 |
content = open(file, 'r', encoding='utf-8', errors='ignore').read()
|
| 229 |
lines = content.splitlines()
|
| 230 |
comments = [line.strip() for line in lines if line.strip()]
|
| 231 |
+
elif file.lower().endswith('.docx'):
|
| 232 |
+
doc = Document(file)
|
| 233 |
+
content = "\n".join([p.text for p in doc.paragraphs])
|
| 234 |
+
parts = re.split(r'[.?!]\s*|\n+', content)
|
| 235 |
+
comments = [p.strip() for p in parts if p.strip()]
|
| 236 |
else:
|
| 237 |
content = open(file, 'r', encoding='utf-8').read()
|
| 238 |
parts = re.split(r'[.?!]\s*|\n+', content)
|
|
|
|
| 287 |
gr.Markdown("Nhập bình luận:")
|
| 288 |
text_input = gr.Textbox(lines=6, placeholder="Nhập bình luận tại đây...", label="")
|
| 289 |
gr.Markdown("Hoặc tải lên tệp .txt hoặc .csv chứa các bình luận:")
|
| 290 |
+
file_input = gr.File(label="Tải tệp", file_types=[".txt", ".csv", ".docx"])
|
| 291 |
predict_button = gr.Button("Dự đoán")
|
| 292 |
output_table = gr.Dataframe(headers=["Comment", "Dự đoán", 'Khả năng tiêu cực', 'Khả năng bình thường', 'Khả năng tích cực'],
|
| 293 |
interactive=False,
|