Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,40 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
demo = gr.Interface(fn=text_generate, inputs="text", outputs="text")
|
13 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
from diffusers import DiffusionPipeline
|
4 |
|
5 |
+
# ζ
δΊζεηζ樑ε
|
6 |
+
text_pipeline = pipeline("text-generation", model="isarth/distill_gpt2_story_generator")
|
7 |
|
8 |
+
# εεηζ樑ε
|
9 |
+
image_pipeline = DiffusionPipeline.from_pretrained("prompthero/openjourney")
|
10 |
+
image_pipeline.to("cuda") # θ₯ι¨η½²η°ε’ζ―ζ΄ GPUοΌι樣ε―ε ιηζ
|
11 |
+
|
12 |
+
# ζεηζε½εΌ
|
13 |
+
def generate_story(input_text):
|
14 |
+
result = text_pipeline(input_text, max_length=200, do_sample=True)
|
15 |
+
story = result[0]["generated_text"]
|
16 |
+
return story
|
17 |
+
|
18 |
+
# εεηζε½εΌ
|
19 |
+
def generate_image_from_story(story_text):
|
20 |
+
image = image_pipeline(story_text).images[0]
|
21 |
+
return image
|
22 |
+
|
23 |
+
# Gradio δ»ι’
|
24 |
+
with gr.Blocks() as demo:
|
25 |
+
gr.Markdown("## β¨ AI ζ
δΊθεηηζε¨")
|
26 |
+
|
27 |
+
with gr.Row():
|
28 |
+
input_text = gr.Textbox(label="θΌΈε
₯δ½ ηζ
δΊιι ", placeholder="εΎι裑ιε§δ½ ηειͺ...")
|
29 |
+
generate_btn = gr.Button("ηζζ
δΊ")
|
30 |
+
|
31 |
+
story_output = gr.Textbox(label="ηζηζ
δΊ")
|
32 |
+
|
33 |
+
with gr.Row():
|
34 |
+
image_btn = gr.Button("ζ Ήζζ
δΊηζεη")
|
35 |
+
image_output = gr.Image(label="ηζηεη")
|
36 |
+
|
37 |
+
generate_btn.click(fn=generate_story, inputs=input_text, outputs=story_output)
|
38 |
+
image_btn.click(fn=generate_image_from_story, inputs=story_output, outputs=image_output)
|
39 |
|
|
|
40 |
demo.launch()
|