Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
class HangmanGame:
|
4 |
def __init__(self):
|
@@ -94,6 +96,26 @@ def guess_interface(guess):
|
|
94 |
message, display, attempts = game.make_guess(guess)
|
95 |
return message, display, attempts
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
# Create Gradio interface
|
98 |
with gr.Blocks() as demo:
|
99 |
gr.Markdown("# 🎲 Gioco dell'Impiccato per Due Giocatori")
|
@@ -105,9 +127,13 @@ with gr.Blocks() as demo:
|
|
105 |
word_display = gr.Textbox(label="Parola", interactive=False)
|
106 |
attempts_display = gr.Number(label="Tentativi Rimasti", interactive=False)
|
107 |
|
|
|
|
|
|
|
|
|
108 |
# Word input section
|
109 |
with gr.Row():
|
110 |
-
word_input = gr.Textbox(label="Primo giocatore: Inserisci una parola segreta")
|
111 |
start_btn = gr.Button("Inizia Gioco")
|
112 |
|
113 |
# Guess input section
|
@@ -127,6 +153,12 @@ with gr.Blocks() as demo:
|
|
127 |
inputs=guess_input,
|
128 |
outputs=[status_output, word_display, attempts_display]
|
129 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
if __name__ == "__main__":
|
132 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import socket
|
3 |
+
import os
|
4 |
|
5 |
class HangmanGame:
|
6 |
def __init__(self):
|
|
|
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:
|
121 |
gr.Markdown("# 🎲 Gioco dell'Impiccato per Due Giocatori")
|
|
|
127 |
word_display = gr.Textbox(label="Parola", interactive=False)
|
128 |
attempts_display = gr.Number(label="Tentativi Rimasti", interactive=False)
|
129 |
|
130 |
+
# Cast link display
|
131 |
+
cast_link_output = gr.Textbox(label="Link per condividere il gioco", interactive=False)
|
132 |
+
generate_link_btn = gr.Button("Genera Link di Condivisione")
|
133 |
+
|
134 |
# Word input section
|
135 |
with gr.Row():
|
136 |
+
word_input = gr.Textbox(label="Primo giocatore: Inserisci una parola segreta", type="password")
|
137 |
start_btn = gr.Button("Inizia Gioco")
|
138 |
|
139 |
# Guess input section
|
|
|
153 |
inputs=guess_input,
|
154 |
outputs=[status_output, word_display, attempts_display]
|
155 |
)
|
156 |
+
|
157 |
+
# Generate cast link action
|
158 |
+
generate_link_btn.click(
|
159 |
+
generate_cast_link,
|
160 |
+
outputs=cast_link_output
|
161 |
+
)
|
162 |
|
163 |
if __name__ == "__main__":
|
164 |
+
demo.launch(server_name="0.0.0.0")
|