TheHickman commited on
Commit
0998fe3
·
verified ·
1 Parent(s): 90d2f9c

Added text2image, gotta add images next

Browse files
Files changed (1) hide show
  1. app.py +80 -6
app.py CHANGED
@@ -284,6 +284,84 @@ await inference.summarization({{
284
  </div>
285
  """
286
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
  # ---- Placeholder HTML pages ----
288
  TEXT_GENERATION_HTML = TEXT_GENERATION
289
 
@@ -291,11 +369,7 @@ QUESTION_ANSWER_HTML = QUESTION_ANSWER
291
 
292
  SUMMARISATION_HTML = SUMMARISE
293
 
294
- IMAGE_GENERATION_HTML = """
295
- <div style="max-width: 800px; margin: auto;">
296
- <h1>Image Generation</h1>
297
- <p>Image generation content goes here...</p>
298
- </div>
299
  """
300
 
301
  # ---- Page switching function ----
@@ -305,7 +379,7 @@ def switch_content(choice):
305
  "Text Generation": TEXT_GENERATION_HTML,
306
  "Question Answering": QUESTION_ANSWER_HTML,
307
  "Summarisation": SUMMARISATION_HTML,
308
- "Image Generation": IMAGE_GENERATION_HTML,
309
  }
310
 
311
  return pages.get(choice, TEXT_GENERATION_HTML)
 
284
  </div>
285
  """
286
 
287
+ TEXT_2_IMAGGE = f"""
288
+ <div id="hf-content" style="max-width: 800px; margin: auto; font-size: 16px; line-height: 1.6;">
289
+ <h1>Text-to-Image (Hugging Face)</h1>
290
+ <p>
291
+ Text-to-image is the task of generating images from input text. These pipelines can also be used to modify and edit images based on text prompts.
292
+ </p>
293
+ <h1>About Text-to-Image</h1>
294
+ <h2>Use Cases</h2>
295
+ <h3>Data Generation</h3>
296
+ <p>
297
+ Businesses can generate data for their use cases by inputting text and getting image outputs.
298
+ </p>
299
+ <h3>Immersive Conversational Chatbots</h3>
300
+ <p>
301
+ Chatbots can be made more immersive if they provide contextual images based on the input provided by the user.
302
+ </p>
303
+ <h3>Creative Ideas for Fashion Industry</h3>
304
+ <p>
305
+ Different patterns can be generated to obtain unique pieces of fashion.
306
+ Text-to-image models make creations easier for designers to conceptualize their design before actually implementing it.
307
+ </p>
308
+ <h3>Architecture Industry </h3>
309
+ <p>
310
+ Architects can utilise the models to construct an environment based out on the requirements of the floor plan.
311
+ This can also include the furniture that has to be placed in that environment.
312
+ </p>
313
+ <h2>Task Variants</h2>
314
+ <h3>Image Editing</h3>
315
+ <p>
316
+ Image editing with text-to-image models involves modifying an image following edit instructions provided in a text prompt.
317
+ <ul>
318
+ <li><b>Synthetic image editing:</b> Adjusting images that were initially created using an input prompt while preserving the overall meaning or context of the original image.</li>
319
+ </ul>
320
+ <ul>
321
+ <li>Real image editing: Similar to synthetic image editing, except we're using real photos/images. This task is usually more complex.</li>
322
+ </ul>
323
+ </p>
324
+ <h3>Personalization</h3>
325
+ <p>
326
+ Personalization refers to techniques used to customize text-to-image models.
327
+ We introduce new subjects or concepts to the model, which the model can then generate when we refer to them with a text prompt.
328
+
329
+ For example, you can use these techniques to generate images of your dog in imaginary settings, after you have taught the model using a few reference images of the subject (or just one in some cases).
330
+ Teaching the model a new concept can be achieved through fine-tuning, or by using training-free techniques.
331
+ </p>
332
+ <h3>Inference</h3>
333
+ <p>
334
+ You can use diffusers pipelines to infer with text-to-image models.
335
+ </p>
336
+ <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
337
+ from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
338
+
339
+ model_id = "stabilityai/stable-diffusion-2"
340
+ scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
341
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, torch_dtype=torch.float16)
342
+ pipe = pipe.to("cuda")
343
+
344
+ prompt = "a photo of an astronaut riding a horse on mars"
345
+ image = pipe(prompt).images[0]
346
+ </pre>
347
+ <p>
348
+ You can use <a href="https://github.com/huggingface/huggingface.js">huggingface.js</a> to infer text-to-image models on Hugging Face Hub.
349
+ </p>
350
+ <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
351
+ import {{} InferenceClient }} from "@huggingface/inference";
352
+
353
+ const inference = new InferenceClient(HF_TOKEN);
354
+ await inference.textToImage({{
355
+ model: "stabilityai/stable-diffusion-2",
356
+ inputs: "award winning high resolution photo of a giant tortoise/((ladybird)) hybrid, [trending on artstation]",
357
+ parameters: {{
358
+ negative_prompt: "blurry",
359
+ }},
360
+ }});
361
+ </pre>
362
+ </div>
363
+ """
364
+
365
  # ---- Placeholder HTML pages ----
366
  TEXT_GENERATION_HTML = TEXT_GENERATION
367
 
 
369
 
370
  SUMMARISATION_HTML = SUMMARISE
371
 
372
+ TEXT_2_IMAGGE_HTML = TEXT_2_IMAGGE
 
 
 
 
373
  """
374
 
375
  # ---- Page switching function ----
 
379
  "Text Generation": TEXT_GENERATION_HTML,
380
  "Question Answering": QUESTION_ANSWER_HTML,
381
  "Summarisation": SUMMARISATION_HTML,
382
+ "Text-to-Image": TEXT_2_IMAGGE_HTML,
383
  }
384
 
385
  return pages.get(choice, TEXT_GENERATION_HTML)