Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
7 |
from nltk.tokenize import sent_tokenize
|
8 |
import plotly.express as px
|
9 |
import time
|
|
|
10 |
nltk.download('punkt')
|
11 |
|
12 |
# Define the model and tokenizer
|
@@ -140,7 +141,7 @@ iface2 = gr.Interface(fn=predict_sdg,
|
|
140 |
|
141 |
# UPLOAD CSV
|
142 |
# Define the prediction function
|
143 |
-
def predict_sdg_from_csv(file):
|
144 |
# Read the CSV file
|
145 |
df_docs = pd.read_csv(file)
|
146 |
text_list = df_docs["text_inputs"].tolist()
|
@@ -170,7 +171,7 @@ def predict_sdg_from_csv(file):
|
|
170 |
prediction_score = []
|
171 |
|
172 |
# Preprocess text and make predictions
|
173 |
-
for text_input in text_list:
|
174 |
time.sleep(0.02) # Sleep to avoid rate limiting
|
175 |
cleaned_text = prep_text(text_input)
|
176 |
tokenized_text = tokenizer(cleaned_text, return_tensors="pt", truncation=True, max_length=512, padding=True)
|
@@ -222,4 +223,4 @@ demo = gr.TabbedInterface(interface_list = [iface1, iface2, iface3],
|
|
222 |
)
|
223 |
|
224 |
# Run the interface
|
225 |
-
demo.launch()
|
|
|
7 |
from nltk.tokenize import sent_tokenize
|
8 |
import plotly.express as px
|
9 |
import time
|
10 |
+
import tqdm
|
11 |
nltk.download('punkt')
|
12 |
|
13 |
# Define the model and tokenizer
|
|
|
141 |
|
142 |
# UPLOAD CSV
|
143 |
# Define the prediction function
|
144 |
+
def predict_sdg_from_csv(file, progress=gr.Progress()):
|
145 |
# Read the CSV file
|
146 |
df_docs = pd.read_csv(file)
|
147 |
text_list = df_docs["text_inputs"].tolist()
|
|
|
171 |
prediction_score = []
|
172 |
|
173 |
# Preprocess text and make predictions
|
174 |
+
for text_input in progress.tqdm(text_list, desc="Analysing data":
|
175 |
time.sleep(0.02) # Sleep to avoid rate limiting
|
176 |
cleaned_text = prep_text(text_input)
|
177 |
tokenized_text = tokenizer(cleaned_text, return_tensors="pt", truncation=True, max_length=512, padding=True)
|
|
|
223 |
)
|
224 |
|
225 |
# Run the interface
|
226 |
+
demo.queue().launch()
|