logo_gen / app.py
broadfield-dev's picture
Update app.py
39dd908 verified
raw
history blame
2.3 kB
import gradio as gr
from huggingface_hub import InferenceClient
import base64
from io import BytesIO
from PIL import Image
import bs4
import lxml
# Define the list of models
models = [
"Qwen/Qwen2.5-Coder-32B-Instruct",
]
def get_webpage_text(url):
source = requests.get(url)
isV('status: ', source.status_code)
if source.status_code ==200:
soup = bs4.BeautifulSoup(source.content,'lxml')
rawp=(f'RAW TEXT RETURNED: {soup.text}')
return rawp
else:
return "ERROR couldn't find, "+url
def generate_image(prompt):
client = InferenceClient("black-forest-labs/FLUX.1-dev")
response = client.text_to_image(prompt)
return response
def generate_prompt(company_name, company_url=""):
client = InferenceClient(model_name)
company_html = get_webpage_text(company_url)
system_prompt=f"""You are a Master Generative Image Prompt Writer, you know just the perfect prompt secrets for every situation
Today you will be generating Company Logo's
You will be given a Company Name, and HTML artifacts from their website, use this to generate a sufficiently long and detailed image generation prompt to satisfy the users request, make sure that the company name is the focal point of the image
Company Name: {company_name}
HTML from Company Website: {company_html}"""
prompt_in=[
{'role':'system','content':system_prompt},
{'role':'user','content':prompt},
]
stream = client.text_generation(prompt_in, **self.generate_kwargs, stream=True, details=True, return_full_text=True)
for response in stream:
output += response.token.text
return output
# Create Gradio Interface
with gr.Blocks() as demo:
gr.Markdown("## Smart Logo Maker")
with gr.Row():
with gr.Column():
model_dropdown = gr.Dropdown(models, label="Select Model")
prompt_input = gr.Textbox(label="Enter Company Name")
prompt_input = gr.Textbox(label="Enter Company Name")
generate_button = gr.Button("Generate Image")
with gr.Column():
output_image = gr.Image(label="Generated Image")
generate_button.click(generate_image, inputs=[prompt_input, model_dropdown], outputs=output_image)
# Launch the interface
demo.launch()