DeepLearning101 commited on
Commit
5bc9aa3
·
verified ·
1 Parent(s): e3972f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -13
app.py CHANGED
@@ -7,6 +7,60 @@ from datasets import Dataset, DatasetDict, load_dataset, load_from_disk
7
  from huggingface_hub import HfApi, HfFolder
8
  from functools import lru_cache
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # 從環境變量中獲取 Hugging Face API 令牌和其他配置
11
  HF_API_TOKEN = os.environ.get("HF_API_TOKEN")
12
  LLM_API = os.environ.get("LLM_API")
@@ -148,29 +202,29 @@ examples = [
148
  ["請問high entropy nitride coatings的形成,主要可透過那些元素來讓這個材料形成熱穩定?"]
149
  ]
150
 
151
- with gr.Blocks() as iface:
152
- gr.HTML(TITLE)
153
- gr.HTML(SUBTITLE)
154
- gr.HTML(LINKS)
155
  with gr.Row():
156
- chatbot = gr.Chatbot()
157
 
158
  with gr.Row():
159
- user_input = gr.Textbox(label='輸入您的問題', placeholder="在此輸入問題...")
160
- submit_button = gr.Button("輸入問題後,請點我送出")
161
 
162
  gr.Examples(examples=examples, inputs=user_input)
163
 
164
  with gr.Row():
165
- like_button = gr.Button(" 👍 覺得答案很好請按我")
166
- dislike_button = gr.Button(" 👎 覺得答案待改善請輸入改進建議後按我")
167
- improvement_input = gr.Textbox(label='請在此輸入改進建議', placeholder='請輸入如何改進模型回應的建議')
168
 
169
  with gr.Row():
170
- feedback_output = gr.Textbox(label='反饋結果', interactive=False)
171
  with gr.Row():
172
- show_feedback_button = gr.Button("查看所有反饋")
173
- feedback_display = gr.JSON(label='所有反饋')
174
 
175
  def chat(user_input, history):
176
  response = handle_user_input(user_input)
 
7
  from huggingface_hub import HfApi, HfFolder
8
  from functools import lru_cache
9
 
10
+ # 定義 CSS 樣式
11
+ custom_css = """
12
+ #title {
13
+ font-size: 2em;
14
+ font-weight: bold;
15
+ text-align: center;
16
+ margin-bottom: 20px;
17
+ }
18
+ #subtitle {
19
+ font-size: 1.5em;
20
+ text-align: center;
21
+ margin-bottom: 20px;
22
+ }
23
+ #links {
24
+ text-align: center;
25
+ margin-bottom: 30px;
26
+ }
27
+ #user_input, #improvement_input, #feedback_output {
28
+ width: 100%;
29
+ margin-bottom: 10px;
30
+ }
31
+ #chatbot {
32
+ height: 500px;
33
+ overflow-y: auto;
34
+ background: #f7f7f7;
35
+ border-radius: 10px;
36
+ padding: 20px;
37
+ border: 1px solid #ccc;
38
+ }
39
+ #feedback_display {
40
+ background: #f7f7f7;
41
+ border-radius: 10px;
42
+ padding: 20px;
43
+ border: 1px solid #ccc;
44
+ }
45
+ .gr-button {
46
+ width: 100%;
47
+ margin-bottom: 10px;
48
+ background-color: #4CAF50;
49
+ color: white;
50
+ border: none;
51
+ padding: 10px 20px;
52
+ text-align: center;
53
+ text-decoration: none;
54
+ display: inline-block;
55
+ font-size: 16px;
56
+ cursor: pointer;
57
+ border-radius: 5px;
58
+ }
59
+ .gr-button:hover {
60
+ background-color: #45a049;
61
+ }
62
+ """
63
+
64
  # 從環境變量中獲取 Hugging Face API 令牌和其他配置
65
  HF_API_TOKEN = os.environ.get("HF_API_TOKEN")
66
  LLM_API = os.environ.get("LLM_API")
 
202
  ["請問high entropy nitride coatings的形成,主要可透過那些元素來讓這個材料形成熱穩定?"]
203
  ]
204
 
205
+ with gr.Blocks(css=custom_css) as iface:
206
+ gr.HTML('<div id="title">TITLE</div>')
207
+ gr.HTML('<div id="subtitle">SUBTITLE</div>')
208
+ gr.HTML('<div id="links">LINKS</div>')
209
  with gr.Row():
210
+ chatbot = gr.Chatbot(elem_id="chatbot")
211
 
212
  with gr.Row():
213
+ user_input = gr.Textbox(label='輸入您的問題', placeholder="在此輸入問題...", elem_id="user_input")
214
+ submit_button = gr.Button("問題輸入好,請點我送出", elem_id="submit_button")
215
 
216
  gr.Examples(examples=examples, inputs=user_input)
217
 
218
  with gr.Row():
219
+ like_button = gr.Button("👍 覺得答案很棒,請按我;或者直接繼續問新問題亦可", elem_id="like_button")
220
+ dislike_button = gr.Button("👎 覺得答案待改善,請輸入改進建議,再按我送出保存", elem_id="dislike_button")
221
+ improvement_input = gr.Textbox(label='請輸入改進建議', placeholder='請輸入如何改進模型回應的建議', elem_id="improvement_input")
222
 
223
  with gr.Row():
224
+ feedback_output = gr.Textbox(label='反饋結果執行狀態', interactive=False, elem_id="feedback_output")
225
  with gr.Row():
226
+ show_feedback_button = gr.Button("查看目前所有反饋記錄", elem_id="show_feedback_button")
227
+ feedback_display = gr.JSON(label='所有反饋記錄', elem_id="feedback_display")
228
 
229
  def chat(user_input, history):
230
  response = handle_user_input(user_input)