Spaces:
Running
Running
File size: 3,283 Bytes
753e5f6 c6f24f8 753e5f6 fcd2b73 2e415e8 753e5f6 c6f24f8 753e5f6 f66af7a c4fdee2 c6f24f8 753e5f6 f66af7a 753e5f6 f66af7a 753e5f6 7a84f3a 753e5f6 42e93b3 8d3409d 42e93b3 8d3409d 42e93b3 f66af7a 753e5f6 f66af7a 753e5f6 42e93b3 43342c7 753e5f6 46e3f65 753e5f6 eec2048 753e5f6 46e3f65 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
import gradio as gr
import requests, base64, io
from dotenv import load_dotenv
import os, datetime, mimetypes
from PIL import Image
load_dotenv()
API_URL = os.environ.get("API_URL", "http://0.0.0.0:8021")
APP_ENV = os.environ.get("APP_ENV", None)
# Assuming the API returns an image URL in the response
def generate_image(campaign_details):
# Define your payload/data to send to the image generation API
data = {
"request_string": campaign_details,
"is_single_image": True
}
# Make the API call
response = requests.post(API_URL + "/generate_graphic", json=data)
# Ensure the API call was successful
if response.status_code != 200:
print(f"Error {response.status_code}: {response.text}")
return "Error: Unable to fetch image from the external API."
# Create the directory if it doesn't exist
image_directory = "images"
if not os.path.exists(image_directory):
os.makedirs(image_directory)
image_path = f"images/temp_image_{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}.png"
with open(image_path, "wb") as image_file:
image_file.write(response.content)
return image_path
content_html = """
<div style="text-align: center; margin-top: 30px;">
<h2>Slidegen Examples</h2>
<div style="display: flex; justify-content: space-around; align-items: center;">
<!-- Displaying one video -->
<video controls width="30%">
<source src="https://cdn-uploads.huggingface.co/production/uploads/644252f59a5bbb07ab7a987a/IxuuqPhmIX3Jggqkeiseb.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<!-- Displaying two images -->
<img src="https://cdn-uploads.huggingface.co/production/uploads/644252f59a5bbb07ab7a987a/f4xH6ZNx1rVbKzr8jAHmt.png" alt="Image Description 1" style="width: 30%; margin: 0 10px;">
<img src="https://cdn-uploads.huggingface.co/production/uploads/644252f59a5bbb07ab7a987a/A9BoWW2ulZycv0OQaihKO.png" alt="Image Description 2" style="width: 30%; margin: 0 10px;">
</div>
</div>
"""
default_value = """
# Brand Name
Enter your brand name here
## Description
Enter your description here.
---
## Branding
### Colors
Primary Color: i.e #000000
Secondary Color: i.e #FFFFFF
### Font
Enter font here i.e Arial
### Logo
Enter your logo url here.
---
## Audience
Enter your target audience here.
---
## Headings
### Main Heading
Your main heading text here.
### Sub-heading
Your sub-heading text here.
---
## Image Layout
### Select Layout
Layout can be any of: Mobile Portrait (750x1334), Mobile Landscape (940x470), Square (2048x2048)
Selected Layout: Mobile Portrait (750x1334)
---
## Custom Graphics
Enter your custom graphic prompt here.
"""
iface = gr.Interface(
fn=generate_image,
inputs=[
gr.components.Textbox(lines=10, placeholder="Enter your Brand and campaign details here", value=default_value, label="Campaign Details")
],
outputs=[
gr.components.Image(label="Generated Image")
],
title="Slidegen AI - Image generator",
article=content_html,
description="Generate social media creatives from a few prompts",
live=False
)
# iface.queue()
# Run the interface
#trigger
iface.launch()
|