Spaces:
Sleeping
Sleeping
Krish Patel
commited on
Commit
·
1a2b17f
1
Parent(s):
a355e59
Debugging 4
Browse files
app.py
CHANGED
|
@@ -51,16 +51,33 @@ st.set_page_config(
|
|
| 51 |
import pandas as pd
|
| 52 |
from final import *
|
| 53 |
|
| 54 |
-
# Cache model loading
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
@st.cache_resource
|
| 56 |
def initialize_models():
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
knowledge_graph = load_knowledge_graph()
|
| 59 |
return nlp, tokenizer, model, knowledge_graph
|
| 60 |
|
| 61 |
-
# Initialize all models
|
| 62 |
-
nlp, tokenizer, model, knowledge_graph = initialize_models()
|
| 63 |
-
|
| 64 |
# Streamlit UI
|
| 65 |
def main():
|
| 66 |
st.title("📰 Nexus NLP News Classifier")
|
|
|
|
| 51 |
import pandas as pd
|
| 52 |
from final import *
|
| 53 |
|
| 54 |
+
# # Cache model loading
|
| 55 |
+
# @st.cache_resource
|
| 56 |
+
# def initialize_models():
|
| 57 |
+
# nlp, tokenizer, model = load_models()
|
| 58 |
+
# knowledge_graph = load_knowledge_graph()
|
| 59 |
+
# return nlp, tokenizer, model, knowledge_graph
|
| 60 |
+
|
| 61 |
+
# # Initialize all models
|
| 62 |
+
# nlp, tokenizer, model, knowledge_graph = initialize_models()
|
| 63 |
+
|
| 64 |
+
# Update the initialize_models function
|
| 65 |
@st.cache_resource
|
| 66 |
def initialize_models():
|
| 67 |
+
try:
|
| 68 |
+
nlp = spacy.load("en_core_web_sm")
|
| 69 |
+
except:
|
| 70 |
+
spacy.cli.download("en_core_web_sm")
|
| 71 |
+
nlp = spacy.load("en_core_web_sm")
|
| 72 |
+
|
| 73 |
+
model_path = "./results/checkpoint-753"
|
| 74 |
+
tokenizer = DebertaV2Tokenizer.from_pretrained('microsoft/deberta-v3-small')
|
| 75 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
| 76 |
+
model.eval()
|
| 77 |
+
|
| 78 |
knowledge_graph = load_knowledge_graph()
|
| 79 |
return nlp, tokenizer, model, knowledge_graph
|
| 80 |
|
|
|
|
|
|
|
|
|
|
| 81 |
# Streamlit UI
|
| 82 |
def main():
|
| 83 |
st.title("📰 Nexus NLP News Classifier")
|
final.py
CHANGED
|
@@ -293,7 +293,7 @@ def load_models():
|
|
| 293 |
|
| 294 |
def load_knowledge_graph():
|
| 295 |
"""Load and initialize knowledge graph"""
|
| 296 |
-
graph_path = "./
|
| 297 |
with open(graph_path, 'rb') as f:
|
| 298 |
graph_data = pickle.load(f)
|
| 299 |
knowledge_graph = nx.DiGraph()
|
|
|
|
| 293 |
|
| 294 |
def load_knowledge_graph():
|
| 295 |
"""Load and initialize knowledge graph"""
|
| 296 |
+
graph_path = "./knowledge_graph_final.pkl"
|
| 297 |
with open(graph_path, 'rb') as f:
|
| 298 |
graph_data = pickle.load(f)
|
| 299 |
knowledge_graph = nx.DiGraph()
|