update upload function (without pd)
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
3 |
-
import
|
4 |
|
5 |
MODEL_URL = "https://huggingface.co/dsfsi/PuoBERTa-News"
|
6 |
WEBSITE_URL = "https://www.kodiks.com/ai_solutions.html"
|
@@ -29,8 +29,9 @@ def prediction(news):
|
|
29 |
|
30 |
def file_prediction(file):
|
31 |
if file.name.endswith('.csv'):
|
32 |
-
|
33 |
-
|
|
|
34 |
else:
|
35 |
file.seek(0)
|
36 |
file_content = file.read().decode('utf-8')
|
@@ -40,12 +41,14 @@ def file_prediction(file):
|
|
40 |
for news in news_list:
|
41 |
if news.strip():
|
42 |
pred = prediction(news)
|
43 |
-
results.append(pred)
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
49 |
|
50 |
|
51 |
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
3 |
+
import csv
|
4 |
|
5 |
MODEL_URL = "https://huggingface.co/dsfsi/PuoBERTa-News"
|
6 |
WEBSITE_URL = "https://www.kodiks.com/ai_solutions.html"
|
|
|
29 |
|
30 |
def file_prediction(file):
|
31 |
if file.name.endswith('.csv'):
|
32 |
+
file.seek(0)
|
33 |
+
reader = csv.reader(file.read().decode('utf-8').splitlines())
|
34 |
+
news_list = [row[0] for row in reader if row]
|
35 |
else:
|
36 |
file.seek(0)
|
37 |
file_content = file.read().decode('utf-8')
|
|
|
41 |
for news in news_list:
|
42 |
if news.strip():
|
43 |
pred = prediction(news)
|
44 |
+
results.append({"news": news, "predictions": pred})
|
45 |
+
|
46 |
+
output = "News Article | Predictions\n"
|
47 |
+
output += "-" * 50 + "\n"
|
48 |
+
for result in results:
|
49 |
+
output += f"{result['news']} | {result['predictions']}\n"
|
50 |
+
return output
|
51 |
+
|
52 |
|
53 |
|
54 |
|