Spaces:
Running
on
T4
Running
on
T4
Nikita
commited on
Commit
·
9568aba
1
Parent(s):
6e15efd
print flush
Browse files
app.py
CHANGED
@@ -4,26 +4,24 @@ import time # Import time to make logs more distinct
|
|
4 |
def greet(name):
|
5 |
"""
|
6 |
This function takes a name as input and returns a personalized greeting string.
|
7 |
-
It now includes print statements for logging
|
|
|
8 |
"""
|
9 |
# Log the function entry
|
10 |
-
|
|
|
11 |
|
12 |
if name:
|
13 |
# Log the received input
|
14 |
-
print(f"[{time.ctime()}] - Received input name: '{name}'")
|
15 |
return f"Hello, {name}! Welcome to your first Gradio app."
|
16 |
else:
|
17 |
# Log that the input was empty
|
18 |
-
print(f"[{time.ctime()}] - No input name received.")
|
19 |
return "Hello! Please enter your name."
|
20 |
|
21 |
# Create the Gradio interface
|
22 |
-
|
23 |
-
# Launch the application
|
24 |
-
if __name__ == "__main__":
|
25 |
-
print(f"[{time.ctime()}] - Starting Gradio server...")
|
26 |
-
gr.Interface(
|
27 |
fn=greet,
|
28 |
inputs=gr.Textbox(
|
29 |
lines=1,
|
@@ -33,4 +31,9 @@ if __name__ == "__main__":
|
|
33 |
outputs=gr.Text(label="Greeting"),
|
34 |
title="Simple Greeting App with Logging",
|
35 |
description="Enter your name to receive a greeting. Check the Hugging Face logs to see the output from the print() statements."
|
36 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
4 |
def greet(name):
|
5 |
"""
|
6 |
This function takes a name as input and returns a personalized greeting string.
|
7 |
+
It now includes print statements for logging with flush=True to ensure
|
8 |
+
logs appear immediately in container environments like Hugging Face Spaces.
|
9 |
"""
|
10 |
# Log the function entry
|
11 |
+
# The flush=True argument is crucial for logs to appear in real-time in Docker.
|
12 |
+
print(f"[{time.ctime()}] - Function 'greet' was called.", flush=True)
|
13 |
|
14 |
if name:
|
15 |
# Log the received input
|
16 |
+
print(f"[{time.ctime()}] - Received input name: '{name}'", flush=True)
|
17 |
return f"Hello, {name}! Welcome to your first Gradio app."
|
18 |
else:
|
19 |
# Log that the input was empty
|
20 |
+
print(f"[{time.ctime()}] - No input name received.", flush=True)
|
21 |
return "Hello! Please enter your name."
|
22 |
|
23 |
# Create the Gradio interface
|
24 |
+
app = gr.Interface(
|
|
|
|
|
|
|
|
|
25 |
fn=greet,
|
26 |
inputs=gr.Textbox(
|
27 |
lines=1,
|
|
|
31 |
outputs=gr.Text(label="Greeting"),
|
32 |
title="Simple Greeting App with Logging",
|
33 |
description="Enter your name to receive a greeting. Check the Hugging Face logs to see the output from the print() statements."
|
34 |
+
)
|
35 |
+
|
36 |
+
# Launch the application
|
37 |
+
if __name__ == "__main__":
|
38 |
+
print(f"[{time.ctime()}] - Starting Gradio server...", flush=True)
|
39 |
+
app.launch(server_name="0.0.0.0", server_port=7860)
|