import requests import os import json STABLE_API = os.getenv("STABLE_API") def generate_image(location, weather, country, description, user_input, additional=""): url = "https://stablediffusionapi.com/api/v3/text2img" if additional: prompt = f"{additional} at {user_input} in {location},{country} with the weather consisting of {weather} and {description}" else: prompt = f"{user_input} in {location},{country} with the weather consisting of {weather} and {description}" payload = json.dumps({ "key": STABLE_API, "prompt": prompt, "negative_prompt": None, "width": "512", "height": "512", "samples": "1", "num_inference_steps": "20", "seed": None, "guidance_scale": 7.5, "safety_checker": "yes", "multi_lingual": "no", "panorama": "no", "self_attention": "no", "upscale": "no", "embeddings_model": None, "webhook": None, "track_id": None }) headers = { 'Content-Type': 'application/json' } response = requests.request("POST", url, headers=headers, data=payload) return response.json()["output"][0]