NikhilJoson commited on
Commit
15219ef
·
verified ·
1 Parent(s): 178d7f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -17,6 +17,7 @@ PIXEL_SIZES = [128, 96, 64, 48, 32, 24, 16, 12, 8, 4, 2]
17
  current_image = None
18
  current_name = None
19
  current_pixel_size = 256
 
20
 
21
  # Function to pixelate an image
22
  def pixelate(image, pixel_size):
@@ -27,11 +28,23 @@ def pixelate(image, pixel_size):
27
 
28
  # Start a new game
29
  def start_game():
30
- global current_image, current_name, current_pixel_size
31
- current_name, image_path = random.choice(list(celebs.items()))
 
 
 
 
 
 
 
 
 
 
 
32
  current_image = Image.open(image_path)
33
  current_pixel_size = PIXEL_SIZES[0]
34
  pixelated_image = pixelate(current_image, current_pixel_size)
 
35
  return pixelated_image, "Image Loaded. Guess the Celebrity!"
36
 
37
  # Reveal more of the image
@@ -54,7 +67,7 @@ def reveal_answer():
54
  return f"The correct answer is: {current_name}!"
55
 
56
  # Create the Gradio interface
57
- with gr.Blocks() as demo:
58
  gr.Markdown("# 🎭 Guess the Celebrity Game!")
59
  gr.Markdown("Can you identify the celebrity as the image becomes clearer?")
60
 
@@ -64,10 +77,10 @@ with gr.Blocks() as demo:
64
  result = gr.Label(label="Game Status")
65
 
66
  with gr.Row():
67
- start_button = gr.Button("Start Game")
68
- clear_button = gr.Button("Clear More")
69
- guess_button = gr.Button("Submit Guess")
70
- reveal_button = gr.Button("Reveal Answer")
71
 
72
  start_button.click(start_game, inputs=[], outputs=[pixelated_image, result])
73
  clear_button.click(clear_more, inputs=[], outputs=[pixelated_image, result])
 
17
  current_image = None
18
  current_name = None
19
  current_pixel_size = 256
20
+ used_images = set() # Track used images
21
 
22
  # Function to pixelate an image
23
  def pixelate(image, pixel_size):
 
28
 
29
  # Start a new game
30
  def start_game():
31
+ global current_image, current_name, current_pixel_size, used_images
32
+
33
+ # Check if all images have been used; if so, reset
34
+ if len(used_images) == len(celebs):
35
+ used_images.clear()
36
+
37
+ # Select a random image that has not been used
38
+ available_images = list(set(celebs.keys()) - used_images)
39
+ current_name = random.choice(available_images)
40
+ used_images.add(current_name)
41
+
42
+ # Load the selected image
43
+ image_path = celebs[current_name]
44
  current_image = Image.open(image_path)
45
  current_pixel_size = PIXEL_SIZES[0]
46
  pixelated_image = pixelate(current_image, current_pixel_size)
47
+
48
  return pixelated_image, "Image Loaded. Guess the Celebrity!"
49
 
50
  # Reveal more of the image
 
67
  return f"The correct answer is: {current_name}!"
68
 
69
  # Create the Gradio interface
70
+ with gr.Blocks(theme=gr.themes.Ocean()) as demo:
71
  gr.Markdown("# 🎭 Guess the Celebrity Game!")
72
  gr.Markdown("Can you identify the celebrity as the image becomes clearer?")
73
 
 
77
  result = gr.Label(label="Game Status")
78
 
79
  with gr.Row():
80
+ start_button = gr.Button("Start Game", variant='huggingface')
81
+ clear_button = gr.Button("Clear More", variant='primary')
82
+ guess_button = gr.Button("Submit Guess", variant='secondary')
83
+ reveal_button = gr.Button("Reveal Answer", variant='success')
84
 
85
  start_button.click(start_game, inputs=[], outputs=[pixelated_image, result])
86
  clear_button.click(clear_more, inputs=[], outputs=[pixelated_image, result])