Spaces:
Sleeping
Sleeping
import gradio as gr | |
# Function for Main content (takes user input and returns a response) | |
def process_input(user_input): | |
return f"You entered: {user_input}" | |
# Function to generate predefined examples | |
def get_example(example): | |
example_root = os.path.join(os.path.dirname(__file__), "examples") | |
# Get list of all example text paths | |
example_files = [os.path.join(example_root, _) for _ in os.listdir(example_root) if _.endswith("txt")] | |
# Read the content of each file (assuming they're text-based PDFs or plain text files) | |
examples = [] | |
for file_path in example_files: | |
example_content = "" | |
with open(file_path, "r", encoding="utf-8", errors="ignore") as f: | |
example_content = f.read() | |
examples.append(example_content) # Read the content and append it to the list | |
return examples | |
# Create the header section | |
def create_header(): | |
with gr.Row(): | |
gr.Markdown("<div id='header'>Welcome to My Gradio App</div>") | |
# Create the user guidance section | |
def create_user_guidance(): | |
with gr.Row(): | |
gr.Markdown("<div id='user-guidance'>Please enter some text below to get started. Select one of the examples to see the output instantly.</div>") | |
# Create the main content section | |
def create_main(): | |
with gr.Row(): | |
with gr.Column(): | |
user_input = gr.Textbox(label="Your Input", placeholder="Enter something here...") | |
output = gr.Textbox(label="Output", interactive=False) | |
user_input.submit(process_input, inputs=user_input, outputs=output) | |
return output # Return the output component for further interactions in other sections | |
# Create the examples section | |
def create_examples(output): | |
examples = get_example | |
with gr.Row(): | |
gr.Markdown("<div id='examples'>Try one of these examples:</div>") | |
example_radio = gr.Radio(choices=examples, label="Select an Example") | |
# When an example is selected, populate the input field | |
example_radio.change(fn=lambda example: example, inputs=example_radio, outputs=user_input) | |
# Create the footer section | |
def create_footer(): | |
with gr.Row(): | |
gr.Markdown("<div id='footer'>© 2025 My Gradio App | All Rights Reserved</div>") | |
# Main function to bring all sections together | |
def ContentAgentUI(): | |
css_path = os.path.join(os.getcwd(), "ui", "styles.css") | |
with gr.Blocks(css=css_path) as ca_gui: | |
create_header() # Create the header | |
create_user_guidance() # Create user guidance section | |
output = create_main() # Create the main section (returns the output component) | |
create_examples(output) # Create the examples section | |
create_footer() # Create the footer section | |
ca_gui.launch() | |