bnoy1 commited on
Commit
5b1c51c
verified
1 Parent(s): 74e1a54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -15
app.py CHANGED
@@ -13,7 +13,7 @@ computer_images = {
13
  "scissors": "computer_scissors.png"
14
  }
15
 
16
- # 讟注讬谞转 诪讜讚诇
17
  checkpoint = "facebook/deit-tiny-patch16-224"
18
  processor = AutoImageProcessor.from_pretrained(checkpoint)
19
  model = AutoModelForImageClassification.from_pretrained(
@@ -24,7 +24,7 @@ model = AutoModelForImageClassification.from_pretrained(
24
  ignore_mismatched_sizes=True
25
  )
26
 
27
- # 讞讜拽讬诐
28
  def game_logic(user_move, computer_move):
29
  if user_move == computer_move:
30
  return "It's a tie!"
@@ -35,8 +35,14 @@ def game_logic(user_move, computer_move):
35
  else:
36
  return "You lose!"
37
 
38
- # 驻讜谞拽爪讬讬转 诪砖讞拽 诪诇讗讛
39
- def play(live_image):
 
 
 
 
 
 
40
  prediction = processor(images=live_image, return_tensors="pt")
41
  outputs = model(**prediction)
42
  logits = outputs.logits
@@ -50,19 +56,11 @@ def play(live_image):
50
 
51
  return live_image, computer_img, f"You chose {user_move}, computer chose {computer_move}. {result}"
52
 
53
- # 住驻讬专讛 诇讗讞讜专 + 诪砖讞拽
54
- def full_play(live_image):
55
- # 住驻讬专讛 诇讗讞讜专
56
- for i in ["3...", "2...", "1...", "GO!"]:
57
- print(i)
58
- time.sleep(1)
59
- return play(live_image)
60
-
61
- # 讘谞讬讬转 讗驻诇讬拽爪讬讛
62
  with gr.Blocks() as demo:
63
  gr.Markdown("# 鉁傦笍 馃 馃搫 Rock Paper Scissors - LIVE Game!")
64
 
65
- webcam = gr.Camera(label="Show your move after countdown!")
66
  play_button = gr.Button("Start Countdown and Play")
67
 
68
  user_output = gr.Image(label="Your Move")
@@ -71,7 +69,7 @@ with gr.Blocks() as demo:
71
 
72
  play_button.click(
73
  fn=full_play,
74
- inputs=[webcam],
75
  outputs=[user_output, computer_output, result_text]
76
  )
77
 
 
13
  "scissors": "computer_scissors.png"
14
  }
15
 
16
+ # 讟注讬谞转 讛诪讜讚诇
17
  checkpoint = "facebook/deit-tiny-patch16-224"
18
  processor = AutoImageProcessor.from_pretrained(checkpoint)
19
  model = AutoModelForImageClassification.from_pretrained(
 
24
  ignore_mismatched_sizes=True
25
  )
26
 
27
+ # 讞讜拽讬 讛诪砖讞拽
28
  def game_logic(user_move, computer_move):
29
  if user_move == computer_move:
30
  return "It's a tie!"
 
35
  else:
36
  return "You lose!"
37
 
38
+ # 住驻讬专讛 诇讗讞讜专 + 诪砖讞拽
39
+ def full_play(live_image):
40
+ # 住驻讬专讛 诇讗讞讜专 讘砖专转 (讬讜驻讬注 讘诇讜讙讬诐)
41
+ for i in ["3...", "2...", "1...", "GO!"]:
42
+ print(i)
43
+ time.sleep(1)
44
+
45
+ # 谞讬转讜讞 转诪讜谞讛
46
  prediction = processor(images=live_image, return_tensors="pt")
47
  outputs = model(**prediction)
48
  logits = outputs.logits
 
56
 
57
  return live_image, computer_img, f"You chose {user_move}, computer chose {computer_move}. {result}"
58
 
59
+ # 讘谞讬讬转 讛讗驻诇讬拽爪讬讛
 
 
 
 
 
 
 
 
60
  with gr.Blocks() as demo:
61
  gr.Markdown("# 鉁傦笍 馃 馃搫 Rock Paper Scissors - LIVE Game!")
62
 
63
+ webcam_input = gr.Image(source="webcam", tool=None, label="Show your move!")
64
  play_button = gr.Button("Start Countdown and Play")
65
 
66
  user_output = gr.Image(label="Your Move")
 
69
 
70
  play_button.click(
71
  fn=full_play,
72
+ inputs=[webcam_input],
73
  outputs=[user_output, computer_output, result_text]
74
  )
75