Text-to-Image
Diffusers
Safetensors
StableDiffusionPipeline
stable-diffusion
stable-diffusion-diffusers
textual_inversion
diffusers-training
Instructions to use aiwithi/Story_Generation with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use aiwithi/Story_Generation with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.bfloat16, device_map="cuda") pipe.load_textual_inversion("aiwithi/Story_Generation") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
Download main.py from aiwithi/Story_Generation: direct link, hf CLI and curl.
- Browser
- Download file 1.38 kB
-
https://huggingface.co/aiwithi/Story_Generation/resolve/main/main.py
- Command line
-
hf download hf://aiwithi/Story_Generation/main.py
-
curl -L -o main.py https://huggingface.co/aiwithi/Story_Generation/resolve/main/main.py
1.38 kB
| import os | |
| import torch | |
| import logging | |
| from flask import Flask, request, jsonify | |
| from flask import send_file | |
| from vllm import LLM | |
| from vllm import SamplingParams | |
| from huggingface_hub import login | |
| import uuid | |
| from llama3 import Llama3 | |
| from stable_diffusion import StableDiffusion | |
| # Initialize Flask app | |
| app = Flask(__name__) | |
| # llama_instance = Llama3() | |
| sd_instance = StableDiffusion() | |
| def generate_text_llama(): | |
| data = request.get_json() | |
| messages = data.get('messages', []) | |
| llm = data.get('llm', 'llama3') | |
| if llm == 'llama3': | |
| response = llama_instance.chat(messages) | |
| else: | |
| return jsonify({"error": "Unsupported LLM"}), 400 | |
| return jsonify({"response": response}) | |
| def generate_image(): | |
| data = request.get_json() | |
| prompt = data.get('prompt', '') | |
| num_inference_steps = data.get('num_inference_steps', 28) | |
| guidance_scale = data.get('guidance_scale', 3.5) | |
| image = sd_instance.generate_image(prompt, num_inference_steps, guidance_scale) | |
| filename = "{}.png".format(str(uuid.uuid4())) | |
| print(f"Generated image filename: {filename}") | |
| sd_instance.save_image(image, filename) | |
| return send_file(filename, mimetype='image/png') | |
| if __name__ == "__main__": | |
| print("Starting the Flask app.") | |
| app.run(host="0.0.0.0", port=5000) |