Spaces:
Running
Running
import gradio as gr | |
from transformers import pipeline | |
# Install required packages | |
import os | |
os.system("pip install -r requirements.txt") | |
# Load the pipeline for text generation | |
pipe = pipeline( | |
"text-generation", | |
model="Ar4ikov/gpt2-650k-stable-diffusion-prompt-generator", | |
tokenizer="gpt2" | |
) | |
# Function to generate text based on input prompt | |
def generate_text(prompt): | |
return pipe(prompt, max_length=77)[0]["generated_text"] | |
# Create a Gradio interface | |
iface = gr.Interface( | |
fn=generate_text, | |
inputs=gr.Textbox(lines=5, label="Prompt"), | |
outputs=gr.Textbox(label="Output", show_copy_button=True), | |
title="<span style='background-image: linear-gradient(to right, #ff7e5f, #feb47b, #ffdb93, #fffbac); -webkit-background-clip: text; -webkit-text-fill-color: transparent;'><center>AI Art Prompt Generator</center></span>", | |
description="Art Prompt Generator is a user-friendly interface designed to optimize input for AI Art Generator or Creator. For faster generation speeds, it's recommended to load the model locally with GPUs, as the online demo at Hugging Face Spaces utilizes CPU, resulting in slower processing times.", | |
api_name="predict" | |
) | |
# Launch the interface | |
iface.launch(show_api=True) |