Spaces:
Running
Running
Update app.py
#2
by
TAgroup5
- opened
app.py
CHANGED
@@ -3,9 +3,19 @@ import pandas as pd
|
|
3 |
import re
|
4 |
import io
|
5 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
6 |
-
|
|
|
|
|
|
|
7 |
|
|
|
|
|
|
|
|
|
8 |
|
|
|
|
|
|
|
9 |
|
10 |
# Load fine-tuned model and tokenizer
|
11 |
model_name = "TAgroup5/news-classification-model"
|
@@ -68,4 +78,9 @@ context = st.text_area("Provide the news article or content for the Q&A:", heigh
|
|
68 |
|
69 |
if question and context.strip():
|
70 |
result = qa_pipeline(question=question, context=context)
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import re
|
4 |
import io
|
5 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
6 |
+
import nltk
|
7 |
+
from nltk.tokenize import word_tokenize
|
8 |
+
from nltk.corpus import stopwords
|
9 |
+
from nltk.stem import WordNetLemmatizer
|
10 |
|
11 |
+
# Download NLTK resources
|
12 |
+
nltk.download('punkt')
|
13 |
+
nltk.download('stopwords')
|
14 |
+
nltk.download('wordnet')
|
15 |
|
16 |
+
# Initialize lemmatizer and stopwords
|
17 |
+
lemmatizer = WordNetLemmatizer()
|
18 |
+
stop_words = set(stopwords.words('english'))
|
19 |
|
20 |
# Load fine-tuned model and tokenizer
|
21 |
model_name = "TAgroup5/news-classification-model"
|
|
|
78 |
|
79 |
if question and context.strip():
|
80 |
result = qa_pipeline(question=question, context=context)
|
81 |
+
|
82 |
+
# Check if the result contains an answer
|
83 |
+
if 'answer' in result and result['answer']:
|
84 |
+
st.write("Answer:", result['answer'])
|
85 |
+
else:
|
86 |
+
st.write("No answer found in the provided content.")
|