Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
from diffusers import DiffusionPipeline | |
# ζ δΊζεηζ樑ε | |
text_pipeline = pipeline("text-generation", model="isarth/distill_gpt2_story_generator") | |
# εεηζ樑ε | |
image_pipeline = DiffusionPipeline.from_pretrained("prompthero/openjourney") | |
# ζεηζε½εΌ | |
def generate_story(input_text): | |
result = text_pipeline(input_text, max_length=200, do_sample=True) | |
story = result[0]["generated_text"] | |
return story | |
# εεηζε½εΌ | |
def generate_image_from_story(story_text): | |
image = image_pipeline(story_text).images[0] | |
return image | |
# Gradio δ»ι’ | |
with gr.Blocks() as demo: | |
gr.Markdown("## β¨ AI ζ δΊθεηηζε¨") | |
with gr.Row(): | |
input_text = gr.Textbox(label="θΌΈε ₯δ½ ηζ δΊιι ", placeholder="εΎι裑ιε§δ½ ηειͺ...") | |
generate_btn = gr.Button("ηζζ δΊ") | |
story_output = gr.Textbox(label="ηζηζ δΊ") | |
with gr.Row(): | |
image_btn = gr.Button("ζ Ήζζ δΊηζεη") | |
image_output = gr.Image(label="ηζηεη") | |
generate_btn.click(fn=generate_story, inputs=input_text, outputs=story_output) | |
image_btn.click(fn=generate_image_from_story, inputs=story_output, outputs=image_output) | |
demo.launch() | |