Emily666666 commited on
Commit
6e1fa6a
1 Parent(s): 659ac69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -13
app.py CHANGED
@@ -1,15 +1,43 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
- def main():
4
- sentiment_pipeline = pipeline("sentiment-analysis")
5
- st.title("Sentiment Analysis with HuggingFace Spaces")
6
- st.write("Enter a sentence to analyze its sentiment:")
7
- user_input = st.text_input("")
8
- if user_input:
9
- result = sentiment_pipeline(user_input)
10
- sentiment = result[0]["label"]
11
- confidence = result[0]["score"]
12
- st.write(f"Sentiment: {sentiment}")
13
- st.write(f"Confidence: {confidence:.2f}")
14
- if __name__ == "__main__":
15
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from transformers import pipeline
3
+
4
+ # Load the text summarization pipeline
5
+ model3_p1 = pipeline("summarization", model="syndi-models/titlewave-t5-base")
6
+
7
+ # Load the classification pipeline
8
+ model_name2_p2 = "elozano/bert-base-cased-news-category"
9
+ classifier = pipeline("text-classification", model=model_name2_p2, return_all_scores=True)
10
+
11
+ # Streamlit app title
12
+ st.title("Question Summarization and Classification")
13
+
14
+ # Tab layout
15
+ tab1, tab2 = st.tabs(["Question Summarization", "Question Classification"])
16
+
17
+ with tab1:
18
+ st.header("Question Summarization")
19
+ # Input text for summarization
20
+ text_to_summarize = st.text_area("Enter question to summarize:", "")
21
+ if st.button("Summarize"):
22
+ # Perform text summarization
23
+ summary = model3_p1(text_to_summarize, max_length=130, min_length=30, do_sample=False)
24
+ # Display the summary result
25
+ st.write("Summary:", summary[0]['summary_text'])
26
+
27
+ with tab2:
28
+ st.header("Question Classification")
29
+ # Input text for news classification
30
+ text_to_classify = st.text_area("Enter question title to classify:", "")
31
+ if st.button("Classify"):
32
+ # Perform question classification
33
+ results = classifier(text_to_classify)[0]
34
+ # Display the classification result
35
+ max_score = float('-inf')
36
+ max_label = ''
37
+ for result in results:
38
+ if result['score'] > max_score:
39
+ max_score = result['score']
40
+ max_label = result['label']
41
+ st.write("Text:", text_to_classify)
42
+ st.write("Category:", max_label)
43
+ st.write("Score:", max_score)