Emily666666 commited on
Commit
e19c3a2
1 Parent(s): 412390e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Load the text summarization pipeline
5
+ try:
6
+ summarizer = pipeline("summarization", model="syndi-models/titlewave-t5-base")
7
+ summarizer_loaded = True
8
+ except ValueError as e:
9
+ st.error(f"Error loading summarization model: {e}")
10
+ summarizer_loaded = False
11
+
12
+ # Load the Question classification pipeline
13
+ model_name = "elozano/bert-base-cased-news-category"
14
+ try:
15
+ classifier = pipeline("text-classification", model=model_name, return_all_scores=True)
16
+ classifier_loaded = True
17
+ except ValueError as e:
18
+ st.error(f"Error loading classification model: {e}")
19
+ classifier_loaded = False
20
+
21
+ # Streamlit app title
22
+ st.title("Question Summarization and Classification")
23
+
24
+ # Input text for summarization and classification
25
+ text_input = st.text_area("Enter long question to summarize and classify:", "")
26
+
27
+ if st.button("Process"):
28
+ if summarizer_loaded and classifier_loaded and text_input:
29
+ try:
30
+ # Perform text summarization
31
+ summary = summarizer(text_input, max_length=130, min_length=30, do_sample=False)
32
+ summarized_text = summary[0]['summary_text']
33
+ # Display the summary result
34
+ st.write("Summary:", summarized_text)
35
+ except Exception as e:
36
+ st.error(f"Error during summarization: {e}")
37
+
38
+ try:
39
+ # Perform question classification on the summarized text
40
+ results = classifier(summarized_text)[0]
41
+ # Find the category with the highest score
42
+ max_score = max(results, key=lambda x: x['score'])
43
+ st.write("Summarized Text:", summarized_text)
44
+ st.write("Category:", max_score['label'])
45
+ st.write("Score:", max_score['score'])
46
+ except Exception as e:
47
+ st.error(f"Error during classification: {e}")
48
+ else:
49
+ st.warning("Please enter text to process and ensure both models are loaded.")