import gradio as gr import os # 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(): # Define the path to the 'examples' directory example_root = os.path.join(os.path.dirname(__file__), "examples") # Get list of all example text file 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 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) # Append the content to the list return examples # Create the header section def create_header(): agent_header = """ #Content Agent """ with gr.Row(): gr.Markdown("") # Create the user guidance section def create_user_guidance(): guidance = """ Please enter text below to get started. The AI Agent will try to determine whether the language is polite and uses the following classification: - `polite` - `somewhat polite` - `neutral` - `impolite` App is running `deepseek-ai/DeepSeek-R1-Distill-Qwen-32B` text generation model. Uses Intel's Polite Guard NLP library. Compute is GCP · Nvidia L4 · 4x GPUs · 96 GB """ with gr.Row(): gr.Markdown("
" + guidance+ "
") # 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...") submit_button = gr.Button("Submit") output = gr.Textbox(label="Content feedback", interactive=False, lines=10, max_lines=20 ) # Define the function to be called when the button is clicked or Enter is pressed submit_button.click(process_input, inputs=user_input, outputs=output) user_input.submit(process_input, inputs=user_input, outputs=output) return user_input, output # Return both input and output components # Create the examples section def create_examples(user_input): # Fetch examples by calling get_example() here examples = get_example() example_radio = gr.Radio(choices=examples, label="Try one of these examples:") # 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("") # Main function to bring all sections together def ContentAgentUI(): # Set the path to the external CSS file 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 user_input, output = create_main() # Create the main section (returns the input/output components) create_examples(user_input) # Create the examples section create_footer() # Create the footer section # Launch the Gradio interface ca_gui.launch()