import gradio as gr import requests def dowload_image(img_url): import random image_url = img_url # Define the local filename to save the image as i = random.choice(range(1,100)) filename = f'downloaded_image{i}.png' response = requests.get(image_url) # Check if the request was successful (status code 200) if response.status_code == 200: # Open the file in write-binary mode ('wb') with open(filename, 'wb') as file: file.write(response.content) print(f"Image downloaded successfully as {filename}!") return filename else: print(f"Failed to download image. Status code: {response.status_code}") def text2Image(prompt): url = "https://ai-text-to-image-generator-flux-free-api.p.rapidapi.com/aaaaaaaaaaaaaaaaaiimagegenerator/quick.php" payload = { "prompt": prompt, "style_id": 4, "size": "1-1" } headers = { "x-rapidapi-key": "21a0339821mshb29d50e4919dc6dp1f25f6jsnbb6b8ece8c63", "x-rapidapi-host": "ai-text-to-image-generator-flux-free-api.p.rapidapi.com", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) response = response.json() img_url = response["result"]["data"]["results"][1]["origin"] return dowload_image(img_url=img_url) gr.Interface( fn=text2Image, inputs=["text"], outputs=["image"], api_name="Testing.." ).launch()