Spaces:
Running
Running
Add application
Browse files
app.py
CHANGED
@@ -1,6 +1,18 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
# Buraya İngilizce modelinizi yazın
|
5 |
model = AutoModelForSequenceClassification.from_pretrained("OsBaran/Roberta-Classification-Model")
|
6 |
tokenizer = AutoTokenizer.from_pretrained("roberta-base")
|
@@ -40,10 +52,7 @@ def explain_roberta_prediction(model, tokenizer, input_text):
|
|
40 |
explanation += "Modelin kararı aşağıdaki anahtar kelimelere dayanıyor:\n" + ', '.join(important_tokens)
|
41 |
|
42 |
return explanation
|
43 |
-
|
44 |
-
from transformers import (AutoTokenizer,
|
45 |
-
AutoModelForSequenceClassification,
|
46 |
-
TextClassificationPipeline)
|
47 |
pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer, return_all_scores=True, device=device)
|
48 |
def score_and_visualize(text):
|
49 |
prediction = pipe([text])
|
@@ -52,13 +61,7 @@ def score_and_visualize(text):
|
|
52 |
explainer = shap.Explainer(pipe)
|
53 |
shap_values = explainer([text])
|
54 |
shap.plots.text(shap_values)
|
55 |
-
|
56 |
-
import re
|
57 |
-
from collections import Counter
|
58 |
-
from sklearn.feature_extraction.text import ENGLISH_STOP_WORDS
|
59 |
-
from bs4 import BeautifulSoup
|
60 |
-
from sklearn.feature_extraction.text import TfidfVectorizer
|
61 |
-
from sklearn.metrics.pairwise import cosine_similarity
|
62 |
api_key = '764e3b45715b449a8aedb8cd8018dfed'
|
63 |
def fetch_news_from_api(api_key, query, page_size=100):
|
64 |
url = f'https://newsapi.org/v2/everything?q={query}&pageSize={page_size}&apiKey={api_key}'
|
@@ -87,7 +90,7 @@ def extract_keywords(text, top_n=5):
|
|
87 |
|
88 |
return [keyword for keyword, _ in most_common_keywords]
|
89 |
|
90 |
-
|
91 |
|
92 |
kw_model = KeyBERT('all-mpnet-base-v2') # SBERT kullanarak modeli yükleyin
|
93 |
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
3 |
+
import shap
|
4 |
+
from transformers import (AutoTokenizer,
|
5 |
+
AutoModelForSequenceClassification,
|
6 |
+
TextClassificationPipeline)
|
7 |
+
import requests
|
8 |
+
import re
|
9 |
+
from collections import Counter
|
10 |
+
from sklearn.feature_extraction.text import ENGLISH_STOP_WORDS
|
11 |
+
from bs4 import BeautifulSoup
|
12 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
13 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
14 |
+
from keybert import KeyBERT
|
15 |
+
import torch
|
16 |
# Buraya İngilizce modelinizi yazın
|
17 |
model = AutoModelForSequenceClassification.from_pretrained("OsBaran/Roberta-Classification-Model")
|
18 |
tokenizer = AutoTokenizer.from_pretrained("roberta-base")
|
|
|
52 |
explanation += "Modelin kararı aşağıdaki anahtar kelimelere dayanıyor:\n" + ', '.join(important_tokens)
|
53 |
|
54 |
return explanation
|
55 |
+
|
|
|
|
|
|
|
56 |
pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer, return_all_scores=True, device=device)
|
57 |
def score_and_visualize(text):
|
58 |
prediction = pipe([text])
|
|
|
61 |
explainer = shap.Explainer(pipe)
|
62 |
shap_values = explainer([text])
|
63 |
shap.plots.text(shap_values)
|
64 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
api_key = '764e3b45715b449a8aedb8cd8018dfed'
|
66 |
def fetch_news_from_api(api_key, query, page_size=100):
|
67 |
url = f'https://newsapi.org/v2/everything?q={query}&pageSize={page_size}&apiKey={api_key}'
|
|
|
90 |
|
91 |
return [keyword for keyword, _ in most_common_keywords]
|
92 |
|
93 |
+
|
94 |
|
95 |
kw_model = KeyBERT('all-mpnet-base-v2') # SBERT kullanarak modeli yükleyin
|
96 |
|