aliabd commited on
Commit
91a656b
Β·
verified Β·
1 Parent(s): f682c12

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. run.ipynb +1 -1
  2. run.py +5 -5
run.ipynb CHANGED
@@ -1 +1 @@
1
- {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: diffusers_with_batching"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio torch transformers diffusers"]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import torch\n", "from diffusers import DiffusionPipeline # type: ignore\n", "import gradio as gr\n", "\n", "generator = DiffusionPipeline.from_pretrained(\"CompVis/ldm-text2im-large-256\")\n", "# move to GPU if available\n", "if torch.cuda.is_available():\n", " generator = generator.to(\"cuda\")\n", "\n", "def generate(prompts):\n", " images = generator(list(prompts)).images # type: ignore\n", " return [images]\n", "\n", "demo = gr.Interface(generate, \n", " \"textbox\", \n", " \"image\", \n", " batch=True, \n", " max_batch_size=4 # Set the batch size based on your CPU/GPU memory\n", ").queue()\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: diffusers_with_batching"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio torch transformers diffusers"]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import torch\n", "from diffusers import DiffusionPipeline # type: ignore\n", "import gradio as gr\n", "\n", "generator = DiffusionPipeline.from_pretrained(\"CompVis/ldm-text2im-large-256\")\n", "# move to GPU if available\n", "if torch.cuda.is_available():\n", " generator = generator.to(\"cuda\")\n", "\n", "def generate(prompts):\n", " images = generator(list(prompts)).images # type: ignore\n", " return [images]\n", "\n", "demo = gr.Interface(generate,\n", " \"textbox\",\n", " \"image\",\n", " batch=True,\n", " max_batch_size=4 # Set the batch size based on your CPU/GPU memory\n", ")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py CHANGED
@@ -11,12 +11,12 @@ def generate(prompts):
11
  images = generator(list(prompts)).images # type: ignore
12
  return [images]
13
 
14
- demo = gr.Interface(generate,
15
- "textbox",
16
- "image",
17
- batch=True,
18
  max_batch_size=4 # Set the batch size based on your CPU/GPU memory
19
- ).queue()
20
 
21
  if __name__ == "__main__":
22
  demo.launch()
 
11
  images = generator(list(prompts)).images # type: ignore
12
  return [images]
13
 
14
+ demo = gr.Interface(generate,
15
+ "textbox",
16
+ "image",
17
+ batch=True,
18
  max_batch_size=4 # Set the batch size based on your CPU/GPU memory
19
+ )
20
 
21
  if __name__ == "__main__":
22
  demo.launch()