Spaces:
Running
on
T4
Running
on
T4
Nikita
commited on
Commit
·
6e15efd
1
Parent(s):
a12343f
logs in test
Browse files
app.py
CHANGED
|
@@ -1,31 +1,28 @@
|
|
| 1 |
-
# First, you need to install the gradio library if you haven't already.
|
| 2 |
-
# You can do this by running the following command in your terminal:
|
| 3 |
-
# pip install gradio
|
| 4 |
-
|
| 5 |
import gradio as gr
|
|
|
|
| 6 |
|
| 7 |
def greet(name):
|
| 8 |
"""
|
| 9 |
This function takes a name as input and returns a personalized greeting string.
|
|
|
|
| 10 |
"""
|
|
|
|
|
|
|
|
|
|
| 11 |
if name:
|
|
|
|
|
|
|
| 12 |
return f"Hello, {name}! Welcome to your first Gradio app."
|
| 13 |
else:
|
|
|
|
|
|
|
| 14 |
return "Hello! Please enter your name."
|
| 15 |
|
| 16 |
# Create the Gradio interface
|
| 17 |
-
# gr.Interface is the main class used to build the UI.
|
| 18 |
-
# - fn: The function that the interface will call.
|
| 19 |
-
# - inputs: The component(s) for user input. Here we use a Textbox.
|
| 20 |
-
# - outputs: The component(s) to display the result. Here we use a simple Text component.
|
| 21 |
-
# - title: The title that appears at the top of the UI.
|
| 22 |
-
# - description: A brief description of what the app does.
|
| 23 |
|
| 24 |
# Launch the application
|
| 25 |
-
# To run in a Docker container (like on Hugging Face Spaces), you must
|
| 26 |
-
# set server_name="0.0.0.0" to listen on all network interfaces.
|
| 27 |
-
# The server_port should match the port exposed in your Dockerfile and readme.md (7860).
|
| 28 |
if __name__ == "__main__":
|
|
|
|
| 29 |
gr.Interface(
|
| 30 |
fn=greet,
|
| 31 |
inputs=gr.Textbox(
|
|
@@ -34,6 +31,6 @@ if __name__ == "__main__":
|
|
| 34 |
label="Your Name"
|
| 35 |
),
|
| 36 |
outputs=gr.Text(label="Greeting"),
|
| 37 |
-
title="Simple Greeting App",
|
| 38 |
-
description="
|
| 39 |
).launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import time # Import time to make logs more distinct
|
| 3 |
|
| 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 |
+
print(f"[{time.ctime()}] - Function 'greet' was called.")
|
| 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(
|
|
|
|
| 31 |
label="Your Name"
|
| 32 |
),
|
| 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 |
).launch(server_name="0.0.0.0", server_port=7860)
|