ServerX commited on
Commit
b1e3bfc
·
verified ·
1 Parent(s): 7dcec97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -20
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
- import socket
3
- import os
4
 
5
  class HangmanGame:
6
  def __init__(self):
@@ -96,25 +96,14 @@ def guess_interface(guess):
96
  message, display, attempts = game.make_guess(guess)
97
  return message, display, attempts
98
 
99
- def get_local_ip():
100
- try:
101
- # Create a temporary socket to get local IP
102
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
103
- s.connect(("8.8.8.8", 80))
104
- local_ip = s.getsockname()[0]
105
- s.close()
106
- return local_ip
107
- except:
108
- return "127.0.0.1"
109
 
110
  def generate_cast_link():
111
- local_ip = get_local_ip()
112
- # Determine the port (default Gradio port)
113
- port = 7860
114
-
115
- # Generate the full link
116
- link = f"http://{local_ip}:{port}"
117
- return link
118
 
119
  # Create Gradio interface
120
  with gr.Blocks() as demo:
@@ -161,4 +150,4 @@ with gr.Blocks() as demo:
161
  )
162
 
163
  if __name__ == "__main__":
164
- demo.launch(server_name="0.0.0.0")
 
1
  import gradio as gr
2
+ import random
3
+ import string
4
 
5
  class HangmanGame:
6
  def __init__(self):
 
96
  message, display, attempts = game.make_guess(guess)
97
  return message, display, attempts
98
 
99
+ def generate_random_subdomain(length=8):
100
+ """Generate a random subdomain for the Hugging Face Spaces URL."""
101
+ return ''.join(random.choices(string.ascii_lowercase + string.digits, k=length))
 
 
 
 
 
 
 
102
 
103
  def generate_cast_link():
104
+ """Generate a Hugging Face Spaces-style share link."""
105
+ subdomain = generate_random_subdomain()
106
+ return f"https://{subdomain}-hangman-game.hf.space/"
 
 
 
 
107
 
108
  # Create Gradio interface
109
  with gr.Blocks() as demo:
 
150
  )
151
 
152
  if __name__ == "__main__":
153
+ demo.launch()