fudii0921 commited on
Commit
c886af8
ยท
verified ยท
1 Parent(s): 3547fac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -22,13 +22,13 @@ def analyze_sentiment(user_input):
22
  # Interpret Results
23
  labels = ["้žๅธธใซๅฆๅฎš็š„ ๐Ÿ˜ก", "ๅฆๅฎš็š„ ๐Ÿ˜ž", "ไธญ็ซ‹็š„ ๐Ÿ˜", "่‚ฏๅฎš็š„ ๐Ÿ™‚", "้žๅธธใซ่‚ฏๅฎš็š„ ๐Ÿ˜"]
24
  sentiment = labels[scores.index(max(scores))] # Select sentiment with highest score
25
-
26
  # Format Confidence Scores
27
  confidence = "\n".join([f"{label}: {score:.2%}" for label, score in zip(labels, scores)])
28
 
29
- return f"ไบˆๆธฌใ•ใ‚ŒใŸๆ„Ÿๆƒ…: {sentiment}", confidence
30
  else:
31
- return "โš ๏ธ Please enter text before analyzing.", ""
32
 
33
  # Gradio Blocks interface
34
  with gr.Blocks() as app:
@@ -36,12 +36,13 @@ with gr.Blocks() as app:
36
  gr.Markdown("ๅˆ†ๆžใ™ใ‚‹ใƒ†ใ‚ญใ‚นใƒˆใ‚’ๅ…ฅๅŠ›ใ—ใฆใใ ใ•ใ„")
37
 
38
  # Text input
39
- user_input = gr.Textbox(label="ๅˆ†ๆžใ™ใ‚‹ใƒ†ใ‚ญใ‚นใƒˆ", info="ใ‚ทใƒณใ‚ฌใƒใƒผใƒซใง้–‹ใ‹ใ‚Œใฆใ„ใ‚‹ใ‚ขใ‚ธใ‚ขๅฎ‰ๅ…จไฟ้šœไผš่ญฐใงๆผ”่ชฌใ—ใŸใ‚ขใƒกใƒชใ‚ซใฎใƒ˜ใ‚ฐใ‚ปใ‚นๅ›ฝ้˜ฒ้•ทๅฎ˜ใŒๅฐๆนพๆƒ…ๅ‹ขใชใฉใ‚’ใ‚ใใ‚Šไธญๅ›ฝใ‚’ๅๆŒ‡ใ—ใ—ใฆ็นฐใ‚Š่ฟ”ใ—้ž้›ฃใ—ใŸใ“ใจใ‚’ๅ—ใ‘ใ€ไธญๅ›ฝๅค–ๅ‹™็œใฏใ‚ขใƒกใƒชใ‚ซๅดใซๆŠ—่ญฐใ—ใŸใ“ใจใ‚’ๆ˜Žใ‚‰ใ‹ใซใ—ใพใ—ใŸใ€‚")
40
 
41
  # Outputs
42
  sentiment_output = gr.Textbox(label="ไบˆๆธฌใ•ใ‚ŒใŸๆ„Ÿๆƒ…", interactive=False)
43
  confidence_output = gr.Textbox(label="็ขบไฟกๅบฆ", interactive=False)
44
-
 
45
  # Button to trigger analysis
46
  analyze_button = gr.Button("ๆ„Ÿๆƒ…ๅˆ†ๆž")
47
 
@@ -49,7 +50,7 @@ with gr.Blocks() as app:
49
  analyze_button.click(
50
  fn=analyze_sentiment,
51
  inputs=[user_input],
52
- outputs=[sentiment_output, confidence_output]
53
  )
54
 
55
  # Launch the Gradio app
 
22
  # Interpret Results
23
  labels = ["้žๅธธใซๅฆๅฎš็š„ ๐Ÿ˜ก", "ๅฆๅฎš็š„ ๐Ÿ˜ž", "ไธญ็ซ‹็š„ ๐Ÿ˜", "่‚ฏๅฎš็š„ ๐Ÿ™‚", "้žๅธธใซ่‚ฏๅฎš็š„ ๐Ÿ˜"]
24
  sentiment = labels[scores.index(max(scores))] # Select sentiment with highest score
25
+
26
  # Format Confidence Scores
27
  confidence = "\n".join([f"{label}: {score:.2%}" for label, score in zip(labels, scores)])
28
 
29
+ return f"ไบˆๆธฌใ•ใ‚ŒใŸๆ„Ÿๆƒ…: {sentiment}", confidence, sentiment # Returning sentiment separately
30
  else:
31
+ return "โš ๏ธ Please enter text before analyzing.", "", ""
32
 
33
  # Gradio Blocks interface
34
  with gr.Blocks() as app:
 
36
  gr.Markdown("ๅˆ†ๆžใ™ใ‚‹ใƒ†ใ‚ญใ‚นใƒˆใ‚’ๅ…ฅๅŠ›ใ—ใฆใใ ใ•ใ„")
37
 
38
  # Text input
39
+ user_input = gr.Textbox(label="ๅˆ†ๆžใ™ใ‚‹ใƒ†ใ‚ญใ‚นใƒˆ", placeholder="ใ“ใ“ใซใƒ†ใ‚ญใ‚นใƒˆใ‚’ๅ…ฅๅŠ›ใ—ใฆใใ ใ•ใ„...")
40
 
41
  # Outputs
42
  sentiment_output = gr.Textbox(label="ไบˆๆธฌใ•ใ‚ŒใŸๆ„Ÿๆƒ…", interactive=False)
43
  confidence_output = gr.Textbox(label="็ขบไฟกๅบฆ", interactive=False)
44
+ top_sentiment_output = gr.Textbox(label="ๆœ€ใ‚‚้ซ˜ใ„ๆ„Ÿๆƒ…", interactive=False) # New output for top sentiment
45
+
46
  # Button to trigger analysis
47
  analyze_button = gr.Button("ๆ„Ÿๆƒ…ๅˆ†ๆž")
48
 
 
50
  analyze_button.click(
51
  fn=analyze_sentiment,
52
  inputs=[user_input],
53
+ outputs=[sentiment_output, confidence_output, top_sentiment_output] # Include new output
54
  )
55
 
56
  # Launch the Gradio app