Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,13 @@
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# Load the text summarization pipeline
|
5 |
try:
|
@@ -27,9 +35,12 @@ text_input = st.text_area("Enter long question to rephrase and classify:", "")
|
|
27 |
if st.button("Process"):
|
28 |
if summarizer_loaded and classifier_loaded and text_input:
|
29 |
try:
|
|
|
|
|
|
|
30 |
# Perform text summarization
|
31 |
-
summary = summarizer(
|
32 |
-
summarized_text = summary[0]['
|
33 |
except Exception as e:
|
34 |
st.error(f"Error during summarization: {e}")
|
35 |
summarized_text = ""
|
|
|
1 |
+
#实现功能:1忽略奇怪符号,直接删掉 2.怎么引用fine-tune的model
|
2 |
+
|
3 |
import streamlit as st
|
4 |
from transformers import pipeline
|
5 |
+
import re
|
6 |
+
|
7 |
+
# Function to remove strange characters from the input text
|
8 |
+
def clean_text(text):
|
9 |
+
# Only keep alphanumeric characters and some punctuation
|
10 |
+
return re.sub(r"[^a-zA-Z0-9\s.,!?']", "", text)
|
11 |
|
12 |
# Load the text summarization pipeline
|
13 |
try:
|
|
|
35 |
if st.button("Process"):
|
36 |
if summarizer_loaded and classifier_loaded and text_input:
|
37 |
try:
|
38 |
+
# Clean the text input
|
39 |
+
cleaned_text = clean_text(text_input)
|
40 |
+
|
41 |
# Perform text summarization
|
42 |
+
summary = summarizer(cleaned_text, max_length=130, min_length=30, do_sample=False)
|
43 |
+
summarized_text = summary[0]['summary_text']
|
44 |
except Exception as e:
|
45 |
st.error(f"Error during summarization: {e}")
|
46 |
summarized_text = ""
|