Spaces:
Runtime error
Runtime error
import gradio as gr | |
from huggingface_hub import InferenceClient | |
# Initialize the HuggingFace Inference Client with the specified model | |
client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.2") | |
def format_prompt(message, logo_request): | |
system_prompt = """ | |
You are an advanced language model designed to create detailed and creative image prompts for logo generation. Based on the user's input, generate an elaborate and descriptive image prompt that can be used to create a high-quality logo. Ensure that the prompt is clear, imaginative, and provides specific details that will guide the logo creation process effectively. | |
""" | |
prompt = f"<s>[SYS] {system_prompt} [/SYS][INST] {logo_request} [/INST]</s>" | |
return prompt | |
def generate(logo_request, temperature=0.9, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0): | |
temperature = float(temperature) | |
if temperature < 1e-2: | |
temperature = 1e-2 | |
top_p = float(top_p) | |
generate_kwargs = { | |
"temperature": temperature, | |
"max_new_tokens": max_new_tokens, | |
"top_p": top_p, | |
"repetition_penalty": repetition_penalty, | |
"do_sample": True, | |
"seed": 42, | |
} | |
formatted_prompt = format_prompt("", logo_request) | |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False) | |
output = "" | |
for response in stream: | |
output += response.token.text | |
yield output | |
css = """ | |
#mkd { | |
height: 500px; | |
overflow: auto; | |
border: 1px solid #ccc; | |
} | |
""" | |
with gr.Blocks(css=css) as gpt: | |
with gr.Row(): | |
with gr.Column(scale=2): | |
gr.HTML("<h1>Settings</h1>") | |
logo_input = gr.Textbox(label="Input your logo request", placeholder="Describe the logo you want...") | |
with gr.Column(scale=3): | |
gr.HTML("<h1><center>Logo Prompt Generator<h1><center>") | |
generate_button = gr.Button("Generate") | |
output_area = gr.Textbox(label="AI Response", interactive=False, lines=10) | |
generate_button.click( | |
fn=generate, | |
inputs=[logo_input], | |
outputs=output_area | |
) | |
gr.Markdown(""" | |
--- | |
### Meta Information | |
**Project Title**: Logo Prompt Generator | |
**Github**: [https://github.com/pacnimo/gpt-prompt-generator](https://github.com/pacnimo/) | |
**Description**: Logo Prompt Generator is Free and Easy to Use. Create a GPT Prompt Based on the Logo Request. 1 Click Prompt Generator. | |
**Footer**: © 2024 by [pacnimo](https://github.com/pacnimo/). All rights reserved. | |
""") # Meta, project description, and footer added here | |
gpt.launch(debug=True) | |