|
from diffusers import DiffusionPipeline |
|
import os |
|
import requests |
|
|
|
def generate_design_image(prompt): |
|
""" |
|
Generate a design image using Hugging Face Diffusers' Stable Diffusion pipeline. |
|
""" |
|
try: |
|
|
|
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2") |
|
pipe.to("cpu") |
|
|
|
|
|
image = pipe(prompt).images[0] |
|
|
|
|
|
output_path = "generated_image.png" |
|
image.save(output_path) |
|
|
|
|
|
return output_path |
|
|
|
except Exception as e: |
|
return f"Error: Failed to generate design image. {str(e)}" |
|
|
|
import requests |
|
import os |
|
|
|
def create_figma_template(task_description): |
|
""" |
|
Create a design template using Figma API. |
|
""" |
|
|
|
FIGMA_API_KEY = os.getenv("FIGMA_API_KEY") |
|
if not FIGMA_API_KEY: |
|
return "Error: Missing FIGMA_API_KEY in environment variables." |
|
|
|
|
|
file_key = "figd_MmKjOOzY45ubfU2sIR9ZTCv5SM8mbDq1aN9x2F9h" |
|
url = f"https://api.figma.com/v1/files/{file_key}" |
|
headers = {"Authorization": f"Bearer {FIGMA_API_KEY}"} |
|
|
|
try: |
|
|
|
response = requests.get(url, headers=headers) |
|
response.raise_for_status() |
|
|
|
|
|
data = response.json() |
|
if "document" in data: |
|
|
|
return f"https://www.figma.com/file/{file_key}" |
|
else: |
|
return f"Error: No valid response received. Response: {data}" |
|
|
|
except requests.exceptions.RequestException as e: |
|
return f"Error: Failed to connect to Figma API. {str(e)}" |
|
except Exception as e: |
|
return f"Error: An unexpected error occurred. {str(e)}" |
|
|
|
|