import os import gradio as gr from transformers import pipeline sd_description = "文字生成图片" sd_examples = [["小猫"], ["cat"], ["dog"]] sd_demo = gr.Interface.load("models/runwayml/stable-diffusion-v1-5", title='文字生成图片', examples=sd_examples) pipe = pipeline("image-classification") examples = [[os.path.join(os.path.dirname(__file__), "lion.jpg")], [os.path.join(os.path.dirname(__file__), "cat.jpeg")]] app = gr.Interface.from_pipeline(pipe, examples=examples, title='图片识别') from diffusers import StableDiffusionPipeline import torch model_id = "dreamlike-art/dreamlike-photoreal-2.0" pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) examples = [["落日"], ["沙滩"]] app_v1 = gr.Interface.from_pipeline(pipe, examples=examples, title='图片生成') demo = gr.TabbedInterface([sd_demo, app, app_v1], ["文字生成图片", "图片识别", "文字生成图片v1"]) demo.launch()