Description: This web application allows users to create images of a specified character in different poses using a consistent character workflow. It leverages the Gradio library for building the interface and handles the image generation process via HTTP requests to a backend server.
Key Features:
- Prompt Input: Users can describe the subject, including details like clothes and hairstyle for better consistency.
- Negative Prompt: Allows specifying elements that should not appear in the generated images, ensuring higher quality and relevance.
- Image Settings:
- Number of Outputs: Number of different images to generate.
- Number of Images Per Pose: Number of images to generate for each specified pose.
- Randomize Poses: Option to randomize poses for variety.
- Output Format: Choice between webp, jpg, and png formats.
- Output Quality: Adjustable quality of the output images.
- Seed: Set a seed for reproducibility of results.
Safety Check: The safety check function uses an external API to verify the appropriateness of the user's prompt. If the prompt is deemed unsafe, the image generation process is halted.
Backend Integration: The application sends a POST request with user inputs to a backend server for processing. It polls the server until the image generation is complete and retrieves the results for display.
Interface: The interface is structured using Gradio's Blocks and Columns, providing a user-friendly layout with advanced settings accessible via an accordion component. The final generated images are displayed in a gallery.
Example Usage:
- Enter a prompt describing the character (e.g., "a person, dark blue suit, black tie, white pocket").
- Optionally, upload an image of the subject for more personalized results.
- Adjust advanced settings such as negative prompt, number of outputs, output format, etc.
- Click "Submit" to generate the images.
Technical Details:
- Libraries Used: Gradio, Requests, Time, OS, Re
- API Integration: Uses an external safety checker API and a local backend for image generation.
- Error Handling: Captures and displays errors to the user if the image generation fails or if the prompt is unsafe.
- Imports and Initialization: Imports necessary libraries and initializes the Gradio client with a Hugging Face token.
- Safety Check Function: Verifies the prompt using the safety checker API.
- Predict Function: Processes user inputs, sends a request to the backend server, and handles the response.
- Gradio Interface: Defines the layout and components of the web application, including text boxes, sliders, checkboxes, dropdowns, and a gallery for displaying results.
- App Launch: Configures and launches the Gradio app with specified settings.
This project exemplifies the use of Gradio for building interactive web applications with robust backend integration and a focus on user experience.