peterchuang commited on
Commit
ce73cf2
·
verified ·
1 Parent(s): be31675

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -5
app.py CHANGED
@@ -3,18 +3,36 @@ import gradio as gr
3
  # 初始數值
4
  hunger = 50
5
  affection = 50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  # 餵食函數
8
  def feed():
9
  global hunger
10
  hunger = max(0, hunger - 10)
11
- return hunger, affection
12
 
13
  # 摸摸函數
14
  def pet():
15
- global affection
16
  affection = min(100, affection + 10)
17
- return hunger, affection
 
18
 
19
  # 建立Gradio介面
20
  with gr.Blocks() as app:
@@ -23,11 +41,13 @@ with gr.Blocks() as app:
23
  hunger_display = gr.Number(value=hunger, label="飢餓度")
24
  affection_display = gr.Number(value=affection, label="親密度")
25
 
 
 
26
  feed_button = gr.Button("餵食肉肉")
27
  pet_button = gr.Button("摸摸他")
28
 
29
- feed_button.click(feed, outputs=[hunger_display, affection_display])
30
- pet_button.click(pet, outputs=[hunger_display, affection_display])
31
 
32
  # 啟動Gradio應用
33
  app.launch()
 
3
  # 初始數值
4
  hunger = 50
5
  affection = 50
6
+ normal_husky = """
7
+ / \\__
8
+ ( @\\___
9
+ / O
10
+ / (_____/
11
+ /_____/ U
12
+ """
13
+
14
+ happy_husky = """
15
+ / \\__
16
+ ( @\\___
17
+ / O
18
+ / (_____/
19
+ /_____/ U ❤️
20
+ """
21
+
22
+ current_husky = normal_husky
23
 
24
  # 餵食函數
25
  def feed():
26
  global hunger
27
  hunger = max(0, hunger - 10)
28
+ return hunger, affection, current_husky
29
 
30
  # 摸摸函數
31
  def pet():
32
+ global affection, current_husky
33
  affection = min(100, affection + 10)
34
+ current_husky = happy_husky
35
+ return hunger, affection, current_husky
36
 
37
  # 建立Gradio介面
38
  with gr.Blocks() as app:
 
41
  hunger_display = gr.Number(value=hunger, label="飢餓度")
42
  affection_display = gr.Number(value=affection, label="親密度")
43
 
44
+ husky_display = gr.Markdown(current_husky)
45
+
46
  feed_button = gr.Button("餵食肉肉")
47
  pet_button = gr.Button("摸摸他")
48
 
49
+ feed_button.click(feed, outputs=[hunger_display, affection_display, husky_display])
50
+ pet_button.click(pet, outputs=[hunger_display, affection_display, husky_display])
51
 
52
  # 啟動Gradio應用
53
  app.launch()