| import gradio as gr | |
| import base64 | |
| import io | |
| from PIL import Image | |
| def text_to_image(prompt): | |
| # This is a placeholder function | |
| # In a real scenario, this would use your actual model | |
| svg_content = f'''<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512"> | |
| <rect width="512" height="512" fill="#f0f0f0"/> | |
| <text x="50%" y="50%" font-size="24" text-anchor="middle" dominant-baseline="middle" font-family="sans-serif"> | |
| {prompt} | |
| </text> | |
| </svg>''' | |
| # Convert SVG to PNG | |
| img = Image.new('RGB', (512, 512), color='white') | |
| return img | |
| # Create Gradio interface | |
| demo = gr.Interface( | |
| fn=text_to_image, | |
| inputs=gr.Textbox(label="Prompt"), | |
| outputs=gr.Image(type="pil", label="Generated Image"), | |
| title="Vector Graphics Generator", | |
| description="Generate vector graphics from text prompts" | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |