Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from sentiment import analyze_sentiment | |
| # Gradio 介面說明 | |
| intro_text = """ | |
| # 🎯 多語言情緒分析 AI | |
| 本應用使用 Hugging Face 的 `XLM-RoBERTa` 模型來進行**多語言情緒分析**。 | |
| 輸入任何語言的文本,AI 會自動判斷其**情緒分類(正向 / 中立 / 負向)**,並提供 AI 判斷的**信心度(%)**。 | |
| ## 🔹 **功能特色** | |
| ✅ **支援多語言**(繁體中文、英文、法文、日文等) | |
| ✅ **即時分析**,不需下載模型 | |
| ✅ **提供信心度**,結果更透明 | |
| ## 📌 **如何使用** | |
| 1️⃣ **輸入一句話或一段文本**(可輸入中文、英文、日文等) | |
| 2️⃣ **點擊「分析情緒」** | |
| 3️⃣ **查看結果,包括情緒分類 & 信心度** | |
| ## ⚠️ **使用須知** | |
| - 目前模型適合**一般文本**,但對**諷刺、幽默**等語句可能不準確。 | |
| - 若遇到分析錯誤,請**重新輸入文本或稍後再試**。 | |
| """ | |
| developer_info = """ | |
| ## 👨💻 開發資訊 | |
| - **開發者**: 余彦志 (大宇 / ian) | |
| - **模型來源**: [Hugging Face](https://huggingface.co/cardiffnlp/twitter-xlm-roberta-base-sentiment) | |
| - **技術棧**: `Gradio`、`FastAPI`、`Hugging Face API` | |
| - **聯絡方式**: [dayuian@hotmail.com] | |
| """ | |
| # 建立 Gradio 介面 | |
| def create_ui(): | |
| with gr.Blocks(theme=gr.themes.Soft()) as iface: | |
| gr.Markdown(intro_text) | |
| with gr.Row(): | |
| text_input = gr.Textbox(lines=3, placeholder="請輸入文本(支援多語言)...", label="輸入文本") | |
| analyze_button = gr.Button("分析情緒") | |
| result_output = gr.Markdown(label="分析結果") | |
| analyze_button.click(analyze_sentiment, inputs=text_input, outputs=result_output) | |
| gr.Markdown(developer_info) | |
| return iface | |