SmilingTree commited on
Commit
4b48512
Β·
verified Β·
1 Parent(s): 266b51d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -7
app.py CHANGED
@@ -1,13 +1,40 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
3
 
4
- pipeline = pipeline("text-generation", model="isarth/distill_gpt2_story_generator")
5
- # pipeline = pipeline("text-generation", model="tohur/natsumura-storytelling-rp-1.0-llama-3.1-8b")
6
 
7
- def text_generate(input_text):
8
- result = pipeline(input_text)
9
- result = result[0]["generated_text"]
10
- return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()