ayaka68 commited on
Commit
671de8b
·
verified ·
1 Parent(s): 5388b96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -39
app.py CHANGED
@@ -519,49 +519,69 @@ def plot_emotion_map(emotion_label, scores, method="AI"):
519
  fontsize=14, fontweight='bold')
520
  plt.tight_layout(); return fig
521
 
522
- # ===== SNS共有ボタン機能を追加 =====
523
- def create_share_buttons(emotion_label, place_name):
524
- """SNS共有ボタンを生成"""
525
- # 共有用のテキスト
526
- share_text = f"Voice × Place Labで感情「{emotion_label}」と診断されました!おすすめの場所は「{place_name}」です。"
527
- encoded_text = urllib.parse.quote(share_text)
528
-
529
- # 現在のページURL(実際のデプロイURLに置き換える必要があります)
530
- page_url = "https://your-app-url.com"
531
- encoded_url = urllib.parse.quote(page_url)
532
-
533
- # Twitter共有リンク
534
- twitter_url = f"https://twitter.com/intent/tweet?text={encoded_text}&url={encoded_url}"
535
-
536
- # Facebook共有リンク
537
- facebook_url = f"https://www.facebook.com/sharer/sharer.php?u={encoded_url}"
538
-
539
- # LINE共有リンク
540
- line_url = f"https://line.me/R/msg/text/?{encoded_text}%20{encoded_url}"
541
-
542
- # ボタンのHTML
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
543
  share_html = f"""
544
- <div style='display: flex; gap: 10px; margin: 20px 0;'>
545
- <a href='{twitter_url}' target='_blank' style='text-decoration: none;'>
546
- <div style='background: #1DA1F2; color: white; padding: 10px 20px; border-radius: 5px; display: inline-block;'>
547
- 🐦 Twitterで共有
548
- </div>
549
- </a>
550
- <a href='{facebook_url}' target='_blank' style='text-decoration: none;'>
551
- <div style='background: #4267B2; color: white; padding: 10px 20px; border-radius: 5px; display: inline-block;'>
552
- 📘 Facebookで共有
553
- </div>
554
- </a>
555
- <a href='{line_url}' target='_blank' style='text-decoration: none;'>
556
- <div style='background: #00B900; color: white; padding: 10px 20px; border-radius: 5px; display: inline-block;'>
557
- 💬 LINEで共有
558
- </div>
559
- </a>
560
  </div>
561
  """
562
-
563
  return share_html
564
-
565
  # ===== メイン =====
566
  def main():
567
  st.set_page_config(page_title="Voice→Place Recommender", page_icon="🎙️", layout="centered")
 
519
  fontsize=14, fontweight='bold')
520
  plt.tight_layout(); return fig
521
 
522
+ import urllib.parse
523
+
524
+ # 共有先URL(固定でOK)
525
+ PAGE_URL = "https://huggingface.co/spaces/ayaka68/voice2place"
526
+ FAC_URL = "https://www.hokusei.ac.jp/informatics/"
527
+ PERSON_URL = "https://aonoa68.github.io/"
528
+
529
+ def _with_utm(url: str, content: str):
530
+ """共有計測用の UTM を付与"""
531
+ u = urllib.parse.urlsplit(url)
532
+ q = urllib.parse.parse_qs(u.query)
533
+ q["utm_source"] = ["hub"]
534
+ q["utm_medium"] = ["social"]
535
+ q["utm_campaign"] = ["oc2025"]
536
+ q["utm_content"] = [content] # twitter / facebook / line
537
+ query = urllib.parse.urlencode(q, doseq=True)
538
+ return urllib.parse.urlunsplit((u.scheme, u.netloc, u.path, query, u.fragment))
539
+
540
+ # ===== SNS共有ボタン機能を追加(改訂版) =====
541
+ def create_share_buttons(emotion_label: str, place_name: str):
542
+ """SNS共有ボタンを生成(学部ページ・個人ページも同梱)"""
543
+ # 共有本文(本文内に学部URL・個人URLも記載)
544
+ share_text = (
545
+ f"Voice × Place Labで「{emotion_label}」と推定。"
546
+ f"おすすめの場所は「{place_name}」。\n"
547
+ f"🎓 情報学部: {_with_utm(FAC_URL, 'body')}\n"
548
+ f"🌐 Onohara: {_with_utm(PERSON_URL, 'body')}\n"
549
+ "#Voice2Place #AI体験"
550
+ )
551
+
552
+ # 各SNS向けのURL(UTM付き)
553
+ page_url_twitter = _with_utm(PAGE_URL, "twitter")
554
+ page_url_facebook = _with_utm(PAGE_URL, "facebook")
555
+ page_url_line = _with_utm(PAGE_URL, "line")
556
+
557
+ enc_text = urllib.parse.quote(share_text)
558
+ enc_url_tw = urllib.parse.quote(page_url_twitter)
559
+ enc_url_fb = urllib.parse.quote(page_url_facebook)
560
+ enc_url_ln = urllib.parse.quote(page_url_line)
561
+
562
+ # Twitter(本文+URL)
563
+ twitter_url = f"https://twitter.com/intent/tweet?text={enc_text}&url={enc_url_tw}"
564
+ # Facebook(URL重視。本文は拾われないためページURLに集約)
565
+ facebook_url = f"https://www.facebook.com/sharer/sharer.php?u={enc_url_fb}"
566
+ # LINE(本文+URLを1メッセージに)
567
+ line_url = f"https://line.me/R/msg/text/?{enc_text}%20{enc_url_ln}"
568
+
569
+ # ボタンHTML(Gradioなら HTML() にそのまま渡せます)
570
  share_html = f"""
571
+ <div style='display:flex;flex-wrap:wrap;gap:10px;margin:20px 0;'>
572
+ <a href='{twitter_url}' target='_blank' rel='noopener noreferrer' style='text-decoration:none'>
573
+ <div style='background:#1DA1F2;color:#fff;padding:10px 16px;border-radius:8px;font-weight:700'>🐦 X(Twitter)で共有</div>
574
+ </a>
575
+ <a href='{facebook_url}' target='_blank' rel='noopener noreferrer' style='text-decoration:none'>
576
+ <div style='background:#4267B2;color:#fff;padding:10px 16px;border-radius:8px;font-weight:700'>📘 Facebookで共有</div>
577
+ </a>
578
+ <a href='{line_url}' target='_blank' rel='noopener noreferrer' style='text-decoration:none'>
579
+ <div style='background:#00B900;color:#fff;padding:10px 16px;border-radius:8px;font-weight:700'>💬 LINEで共有</div>
580
+ </a>
 
 
 
 
 
 
581
  </div>
582
  """
 
583
  return share_html
584
+
585
  # ===== メイン =====
586
  def main():
587
  st.set_page_config(page_title="Voice→Place Recommender", page_icon="🎙️", layout="centered")