Spaces:
Runtime error
Runtime error
import re | |
import os | |
import requests | |
import gradio as gr | |
from datasets import load_dataset | |
from PIL import Image | |
from io import BytesIO | |
import torch | |
from torch import autocast | |
from transformers import pipeline, set_seed | |
from diffusers import DiffusionPipeline, StableDiffusionPipeline | |
# Config | |
DEVICE = "cuda" | |
# GPT2 | |
def get_gpt2_pipeline(): | |
generator = pipeline('text-generation', model='gpt2') | |
set_seed(42) | |
# generator("Hello world, I'm vizard,", max_length=50, num_return_sequences=3) | |
return generator | |
# SD v1.4 | |
def get_stable_diffusion_v14_pipeline(): | |
model_id = "CompVis/stable-diffusion-v1-4" | |
pipe = StableDiffusionPipeline.from_pretrained(mode_id) | |
# pipeline = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True, revision="fp16", torch_dtype=torch.float16) | |
pipe = pipe.to(DEVICE) | |
torch.backends.cudnn.benchmark = True | |
return pipe | |
# SD v1.5 | |
def get_stable_diffusion_v15_pipeline(): | |
model_id = "runwayml/stable-diffusion-v1-5" | |
pipe = DiffusionPipeline.from_pretrained(mode_id) | |
pipe = pipe.to(DEVICE) | |
return pipe | |
def get_image(url): | |
response = requests.get(url) | |
image = Image.open(BytesIO(response.content)).convert("RGB") | |
resized_image = image.resize((768, 512)) | |
return resized_image | |
# main | |
def main(): | |
prompt = "Hello world, I'm vizard," | |
pipe = pipeline(task="image-classification", | |
model="microsoft/dit-base-finetuned-rvlcdip") | |
gr.Interface.from_pipeline(pipe, | |
title=title, | |
description=description, | |
examples=['coca_cola_advertisement.png', 'scientific_publication.png', 'letter.jpeg'], | |
article=article, | |
enable_queue=True, | |
).launch() | |
# pipe2 = get_stable_diffusion_v15_pipeline() | |
# images = pipe2(prompt).images | |
main |