TharushiPerera commited on
Commit
529a69e
Β·
verified Β·
1 Parent(s): 8a98646

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -19,7 +19,11 @@ def load_text_classifier():
19
 
20
  # Load Classifier & QA pipeline
21
  classifier = load_text_classifier()
22
- qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
 
 
 
 
23
 
24
  # ----------------- CSS Styling -----------------
25
  st.markdown(
@@ -45,7 +49,7 @@ uploaded_file = st.file_uploader("Choose a CSV file...", type=["csv"])
45
 
46
  if uploaded_file:
47
  # Read and preprocess
48
- df = pd.read_csv(uploaded_file)
49
  if "content" not in df.columns:
50
  st.error("❌ The uploaded CSV must contain a 'content' column.")
51
  st.stop()
@@ -63,7 +67,8 @@ if uploaded_file:
63
 
64
  # ----------------- Download -----------------
65
  st.subheader("πŸ“₯ Download Results")
66
- csv_output = df.to_csv(index=False).encode('utf-8')
 
67
  st.download_button("Download Output CSV", data=csv_output, file_name="output.csv", mime="text/csv")
68
 
69
  # ----------------- Q&A Section -----------------
@@ -71,14 +76,14 @@ if uploaded_file:
71
  question = st.text_input("πŸ” What do you want to know about the content?")
72
 
73
  if st.button("Get Answer"):
74
- context = " ".join(df['cleaned_text'].tolist())
75
  with st.spinner("Answering..."):
76
  result = qa_pipeline(question=question, context=context)
77
- st.success(f"πŸ“ **Answer:** {result['answer']}")
78
 
79
  # ----------------- Word Cloud -----------------
80
- st.subheader("☁️ Word Cloud of News Text")
81
- text = " ".join(df['cleaned_text'].tolist())
82
  wordcloud = WordCloud(width=800, height=400, background_color="white").generate(text)
83
 
84
  fig, ax = plt.subplots()
 
19
 
20
  # Load Classifier & QA pipeline
21
  classifier = load_text_classifier()
22
+ qa_pipeline = pipeline(
23
+ "question-answering",
24
+ model="deepset/roberta-large-squad2",
25
+ tokenizer="deepset/roberta-large-squad2"
26
+ )
27
 
28
  # ----------------- CSS Styling -----------------
29
  st.markdown(
 
49
 
50
  if uploaded_file:
51
  # Read and preprocess
52
+ df = pd.read_csv(uploaded_file, encoding='utf-8')
53
  if "content" not in df.columns:
54
  st.error("❌ The uploaded CSV must contain a 'content' column.")
55
  st.stop()
 
67
 
68
  # ----------------- Download -----------------
69
  st.subheader("πŸ“₯ Download Results")
70
+ output_df = df[['content', 'class']]
71
+ csv_output = output_df.to_csv(index=False, encoding='utf-8-sig').encode('utf-8-sig')
72
  st.download_button("Download Output CSV", data=csv_output, file_name="output.csv", mime="text/csv")
73
 
74
  # ----------------- Q&A Section -----------------
 
76
  question = st.text_input("πŸ” What do you want to know about the content?")
77
 
78
  if st.button("Get Answer"):
79
+ context = " ".join(df['content'].tolist())
80
  with st.spinner("Answering..."):
81
  result = qa_pipeline(question=question, context=context)
82
+ st.success(f"πŸ“ Answer: {result['answer']}")
83
 
84
  # ----------------- Word Cloud -----------------
85
+ st.subheader("☁ Word Cloud of News Text")
86
+ text = " ".join(df['content'].tolist())
87
  wordcloud = WordCloud(width=800, height=400, background_color="white").generate(text)
88
 
89
  fig, ax = plt.subplots()