Emily666666 commited on
Commit
9f7bad0
1 Parent(s): 79687df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -1,5 +1,3 @@
1
- #实现功能:1忽略奇怪符号,直接删掉 2.怎么引用fine-tune的model
2
-
3
  import streamlit as st
4
  from transformers import pipeline
5
  import re
@@ -26,6 +24,20 @@ except ValueError as e:
26
  st.error(f"Error loading classification model: {e}")
27
  classifier_loaded = False
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  # Streamlit app title
30
  st.title("Question Rephrase and Classification")
31
 
@@ -51,8 +63,10 @@ if st.button("Process"):
51
  results = classifier(summarized_text)[0]
52
  # Find the category with the highest score
53
  max_score = max(results, key=lambda x: x['score'])
 
 
54
  st.write("Rephrased Text:", summarized_text)
55
- st.write("Category:", max_score['label'])
56
  st.write("Score:", max_score['score'])
57
  except Exception as e:
58
  st.error(f"Error during classification: {e}")
 
 
 
1
  import streamlit as st
2
  from transformers import pipeline
3
  import re
 
24
  st.error(f"Error loading classification model: {e}")
25
  classifier_loaded = False
26
 
27
+ # Dictionary to map numerical labels to real labels
28
+ label_mapping = {
29
+ 0: "Society & Culture",
30
+ 1: "Science & Mathematics",
31
+ 2: "Health",
32
+ 3: "Education & Reference",
33
+ 4: "Computers & Internet",
34
+ 5: "Sports",
35
+ 6: "Business & Finance",
36
+ 7: "Entertainment & Music",
37
+ 8: "Family & Relationships",
38
+ 9: "Politics & Government"
39
+ }
40
+
41
  # Streamlit app title
42
  st.title("Question Rephrase and Classification")
43
 
 
63
  results = classifier(summarized_text)[0]
64
  # Find the category with the highest score
65
  max_score = max(results, key=lambda x: x['score'])
66
+ predicted_label_index = int(max_score['label'].split('_')[-1]) # Assuming labels are like "LABEL_0", "LABEL_1", etc.
67
+ predicted_label = label_mapping[predicted_label_index]
68
  st.write("Rephrased Text:", summarized_text)
69
+ st.write("Category:", predicted_label)
70
  st.write("Score:", max_score['score'])
71
  except Exception as e:
72
  st.error(f"Error during classification: {e}")