Spaces:
Sleeping
Sleeping
File size: 1,554 Bytes
c300f7f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import gradio as gr
import os
def get_space_info():
"""
Retrieves the Hugging Face Space owner and repository name from environment variables.
Returns a formatted string with the information.
"""
space_author = os.getenv("SPACE_AUTHOR_NAME")
space_repo = os.getenv("SPACE_REPO_NAME")
if space_author and space_repo:
return f"This Space is owned by: **{space_author}**\n\n" \
f"The repository name is: **{space_repo}**\n\n" \
f"Full Space ID: `{space_author}/{space_repo}`"
else:
return "Not currently running in a Hugging Face Space environment, or required environment variables are not set.\n\n" \
"To see this work, deploy this code to a Hugging Face Space!"
# Create the Gradio interface
with gr.Blocks() as demo:
gr.Markdown(
"""
# Hugging Face Space Info Viewer
Click the button below to retrieve and display the owner and repository name
of this Hugging Face Space.
"""
)
# Output component to display the information
output_text = gr.Textbox(label="Space Details", lines=5, interactive=False)
# Button to trigger the function
get_info_btn = gr.Button("Get Space Info")
# Define the interaction: when the button is clicked, call get_space_info and update output_text
get_info_btn.click(
fn=get_space_info,
inputs=[], # No inputs needed for this function
outputs=[output_text]
)
# Launch the Gradio app
if __name__ == "__main__":
demo.launch() |