This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #@title Demo UI | |
| import gradio as gr | |
| import numpy as np | |
| def generate_image(seed, c0, c1, c2, c3, c4, c5, c6): | |
| seed = int(seed) | |
| params = {'c0': c0, | |
| 'c1': c1, | |
| 'c2': c2, | |
| 'c3': c3, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #@title Define functions | |
| def display_sample_pytorch(seed, truncation, directions, distances, scale, start, end, w=None, disp=True, save=None, noise_spec=None): | |
| # blockPrint() | |
| model.truncation = truncation | |
| if w is None: | |
| w = model.sample_latent(1, seed=seed).detach().cpu().numpy() | |
| w = [w]*model.get_max_latents() # one per layer | |
| else: | |
| w = [np.expand_dims(x, 0) for x in w] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #@title Load Model | |
| # The model name, change this only | |
| selected_model = 'lookbook' | |
| # Load model | |
| import torch | |
| import numpy as np | |
| from PIL import Image | |
| from models import get_instrumented_model | |
| from decomposition import get_or_compute |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| sys.path.append("clipit") | |
| import clipit | |
| # To reset settings to default | |
| clipit.reset_settings() | |
| # You can use "|" to separate multiple prompts | |
| prompts = "underwater city" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch | |
| import clipit | |
| import time | |
| from datetime import datetime | |
| import firebase_admin | |
| from firebase_admin import credentials, firestore, storage | |
| if not firebase_admin._apps: | |
| cred = credentials.Certificate("YOUR_CREDENTIAL_FILE") | |
| firebase_admin.initialize_app(cred, { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #@title API Functions | |
| import clipit | |
| import torch | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi import FastAPI, File, UploadFile, Form, BackgroundTasks | |
| from fastapi.responses import FileResponse | |
| app = FastAPI() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| def email_results_mailgun(email, prompt): | |
| return requests.post("https://api.mailgun.net/v3/text2art.com/messages", | |
| auth=("api", "YOUR_MAILGUN_API_KEY"), | |
| files=[("attachment",("output.png", open("output.png", "rb").read() )), | |
| ("attachment", ("output.mp4", open("output.mp4", "rb").read() ))], | |
| data={"from": "Text2Art <YOUR_EMAIL>", | |
| "to": email, | |
| "subject": "Your Artwork is ready!", | |
| "text": f'Your generated arts using the prompt "{prompt}".', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import nest_asyncio | |
| from pyngrok import ngrok | |
| import uvicorn | |
| ngrok_tunnel = ngrok.connect(8000) | |
| print('Public URL:', ngrok_tunnel.public_url) | |
| print('Doc URL:', ngrok_tunnel.public_url+'/docs') | |
| nest_asyncio.apply() | |
| uvicorn.run(app, port=8000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import clipit | |
| import torch | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi import FastAPI, File, UploadFile, Form, BackgroundTasks | |
| from fastapi.responses import FileResponse | |
| app = FastAPI() | |
| app.add_middleware( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import gradio as gr | |
| import torch | |
| import clipit | |
| # Define the main function | |
| def generate(prompt, quality, style, aspect): | |
| torch.cuda.empty_cache() | |
| clipit.reset_settings() | |
| use_pixeldraw = (style == 'pixel art') |
NewerOlder