joey1101 commited on
Commit
2bee048
·
verified ·
1 Parent(s): 5526f12

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -1,11 +1,11 @@
1
  !pip install huggingface_hub
2
- !pip install --upgrade transformers
3
  !pip install datasets soundfile
4
 
5
  ##########################################
6
  # Step 0: 导入必需的库
7
  ##########################################
8
-
9
  from transformers import pipeline, SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan, AutoModelForCausalLM, AutoTokenizer, pipeline
10
  from datasets import load_dataset
11
  from IPython.display import Audio, display
@@ -16,10 +16,19 @@ from google.colab import drive
16
 
17
  from huggingface_hub import login
18
 
 
 
 
 
 
 
 
19
 
20
  ##########################################
21
  # Step 1:情感分析 - 分析用户评论的情感倾向
22
  ##########################################
 
 
23
 
24
  pipe = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base")
25
 
@@ -37,10 +46,15 @@ user_review = "I love the fast delivery, but the product quality could be better
37
  emotion_results = emotion_classifier(user_review)[0] # 返回列表中的第一个结果(单条输入)
38
 
39
  # 打印所有情感维度及其分数
 
40
  print("情感分析结果(多维度):")
41
  for emotion in emotion_results:
42
  print(f"{emotion['label']}: {emotion['score']:.4f}")
43
-
 
 
 
 
44
  # 提取置信度最高的情感标签(可选)
45
  dominant_emotion = max(emotion_results, key=lambda x: x['score'])
46
  print("\n主导情感:", dominant_emotion['label'], f"(置信度: {dominant_emotion['score']:.2f})")
 
1
  !pip install huggingface_hub
2
+ !pip install transformers
3
  !pip install datasets soundfile
4
 
5
  ##########################################
6
  # Step 0: 导入必需的库
7
  ##########################################
8
+ import streamlit as st
9
  from transformers import pipeline, SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan, AutoModelForCausalLM, AutoTokenizer, pipeline
10
  from datasets import load_dataset
11
  from IPython.display import Audio, display
 
16
 
17
  from huggingface_hub import login
18
 
19
+ # Streamlit application title
20
+ st.title("Comment reply for you")
21
+ st.write("automative reply")
22
+
23
+ # Text input for user to enter the comment
24
+ text = st.text_area("Enter your comment", "")
25
+
26
 
27
  ##########################################
28
  # Step 1:情感分析 - 分析用户评论的情感倾向
29
  ##########################################
30
+ # Perform tasks when the user clicks the "Comment" button
31
+ if st.button("Comment"):
32
 
33
  pipe = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base")
34
 
 
46
  emotion_results = emotion_classifier(user_review)[0] # 返回列表中的第一个结果(单条输入)
47
 
48
  # 打印所有情感维度及其分数
49
+
50
  print("情感分析结果(多维度):")
51
  for emotion in emotion_results:
52
  print(f"{emotion['label']}: {emotion['score']:.4f}")
53
+
54
+ st.write("Text:", text)
55
+ st.write("Label:", max_label)
56
+ st.write("Score:", max_score)
57
+
58
  # 提取置信度最高的情感标签(可选)
59
  dominant_emotion = max(emotion_results, key=lambda x: x['score'])
60
  print("\n主导情感:", dominant_emotion['label'], f"(置信度: {dominant_emotion['score']:.2f})")