Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import
|
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
|
100 |
-
|
101 |
-
|
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 |
-
|
112 |
-
|
113 |
-
|
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(
|
|
|
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()
|