Spaces:
Sleeping
Sleeping
Update model.py
Browse files
model.py
CHANGED
|
@@ -13,6 +13,7 @@ import torch
|
|
| 13 |
from transformers import AutoTokenizer, BertForSequenceClassification
|
| 14 |
from datasets import Dataset
|
| 15 |
import pandas as pd
|
|
|
|
| 16 |
import re
|
| 17 |
from hazm import Normalizer, Lemmatizer, word_tokenize, stopwords_list
|
| 18 |
|
|
@@ -100,6 +101,11 @@ def process_sentence(sentence):
|
|
| 100 |
return f"Type: {sentence_type}\nSentiment: {sentiment}\nCleaned Text: {cleaned}"
|
| 101 |
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
# Function to process file
|
| 105 |
def process_file(file):
|
|
@@ -113,8 +119,10 @@ def process_file(file):
|
|
| 113 |
df['Type'] = df['Comment'].apply(classify_sentence)
|
| 114 |
df['Sentiment'] = df['Comment'].apply(predict_sentiment_labels)
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
| 119 |
except Exception as e:
|
| 120 |
return str(e)
|
|
|
|
| 13 |
from transformers import AutoTokenizer, BertForSequenceClassification
|
| 14 |
from datasets import Dataset
|
| 15 |
import pandas as pd
|
| 16 |
+
import os
|
| 17 |
import re
|
| 18 |
from hazm import Normalizer, Lemmatizer, word_tokenize, stopwords_list
|
| 19 |
|
|
|
|
| 101 |
return f"Type: {sentence_type}\nSentiment: {sentiment}\nCleaned Text: {cleaned}"
|
| 102 |
|
| 103 |
|
| 104 |
+
# ایجاد پوشه برای ذخیره فایلها در صورت نبود آن
|
| 105 |
+
output_folder = "./outputs"
|
| 106 |
+
if not os.path.exists(output_folder):
|
| 107 |
+
os.makedirs(output_folder)
|
| 108 |
+
|
| 109 |
|
| 110 |
# Function to process file
|
| 111 |
def process_file(file):
|
|
|
|
| 119 |
df['Type'] = df['Comment'].apply(classify_sentence)
|
| 120 |
df['Sentiment'] = df['Comment'].apply(predict_sentiment_labels)
|
| 121 |
|
| 122 |
+
processed_file_path = os.path.join(output_folder, "processed_file.csv")
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
df.to_csv(processed_file_path, index=False)
|
| 126 |
+
return processed_file_path
|
| 127 |
except Exception as e:
|
| 128 |
return str(e)
|