File size: 2,859 Bytes
f7235bd
 
62d9bf1
 
 
ffc2d49
a0f0447
39dd908
 
62d9bf1
f7235bd
39dd908
f7235bd
39dd908
 
 
 
 
 
 
 
 
 
bcab8fb
7eb5701
be8ba36
39dd908
 
bcab8fb
be8ba36
 
bcab8fb
39dd908
 
 
 
 
d848380
 
 
 
 
 
 
 
a0f0447
39dd908
 
 
f7235bd
bcab8fb
69364eb
c5b8f4f
 
69364eb
c5b8f4f
 
bcab8fb
 
2abf06b
bcab8fb
 
f7235bd
 
39dd908
f7235bd
 
bcab8fb
 
 
f7235bd
 
 
 
bcab8fb
f7235bd
 
 
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
import gradio as gr
from huggingface_hub import InferenceClient
import base64
from io import BytesIO
from PIL import Image
import requests
import random
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_prompt(company_name, company_html, company_descp):
    client = InferenceClient(models[0])
    output=""
    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, Description, 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
    """
    prompt=f"""Company Name: {company_name}
    Company Description: {company_descp}
    HTML from Company Website: {company_html}"""
    prompt_in=[
        {'role':'system','content':system_prompt},
        {'role':'user','content':prompt},
    ]
    generate_kwargs = dict(
        temperature=0.99,
        max_new_tokens=512, #total tokens - input tokens
        top_p=0.99,
        repetition_penalty=1.0,
        do_sample=True,
        seed=random.randint(1,100000000000000),
    )
    stream = client.text_generation(prompt_in, **generate_kwargs, stream=True, details=True, return_full_text=True)
    for response in stream:
        output += response.token.text
    return output

        
def generate_image(comp_name, comp_desc="", comp_url=""):
    if comp_url:
        web_out=get_webpage_text(comp_url)
        print(web_out)
    else:
        web_out="No Web Data returned"
    prompt_out=generate_prompt(comp_name,web_out, comp_desc)
    client = InferenceClient("black-forest-labs/FLUX.1-dev")
    response = client.text_to_image(prompt_out)
    return response

# Create Gradio Interface
with gr.Blocks() as demo:
    gr.Markdown("## Smart Logo Maker")
    with gr.Row():
        with gr.Column():
            comp_name = gr.Textbox(label="Enter Company Name")
            comp_desc = gr.Textbox(label="Enter Company Description (optional)")
            comp_url = gr.Textbox(label="Enter Company URL (optional)")
            generate_button = gr.Button("Generate Image")
        with gr.Column():
            output_image = gr.Image(label="Generated Image")
    
    generate_button.click(generate_image, inputs=[comp_name, comp_desc, comp_url], outputs=output_image)

# Launch the interface
demo.launch()