Spaces:
Sleeping
Sleeping
File size: 1,292 Bytes
2fadb29 a4b8965 4b48512 a4b8965 4b48512 2fadb29 4b48512 2fadb29 |
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 |
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()
|