djrana commited on
Commit
7186c16
1 Parent(s): a9d5136

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -25
app.py CHANGED
@@ -1,30 +1,12 @@
1
  import gradio as gr
2
- import os
3
- import requests
4
- import random
5
- import time
6
  from transformers import AutoTokenizer, AutoModelForCausalLM
7
  import torch
8
  from PIL import Image
9
- from transformers import pipeline
10
- from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
11
-
12
- # Load the pipeline for text generation
13
- text_generator = pipeline(
14
- "text-generation",
15
- model="Ar4ikov/gpt2-650k-stable-diffusion-prompt-generator",
16
- tokenizer="gpt2"
17
- )
18
 
19
- # Load tokenizer and model for image generation
20
  tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-2.7B")
21
  model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neo-2.7B")
22
 
23
- # Function to generate text based on input prompt
24
- def generate_text(prompt):
25
- return text_generator(prompt, max_length=77)[0]["generated_text"]
26
-
27
- # Function to generate image based on input text
28
  def generate_image(text):
29
  # Tokenize input text
30
  input_ids = tokenizer.encode(text, return_tensors="pt")
@@ -42,13 +24,13 @@ def generate_image(text):
42
 
43
  # Create Gradio interface
44
  iface = gr.Interface(
45
- fn=[generate_text, generate_image],
46
- inputs=["textbox", "textbox"],
47
- outputs=["textbox", "image"],
48
- title="AI Art Prompt Generator",
49
- description="Art Prompt Generator is a user-friendly interface designed to optimize input for AI Art Generator or Creator. For faster generation speeds, it's recommended to load the model locally with GPUs, as the online demo at Hugging Face Spaces utilizes CPU, resulting in slower processing times.",
50
  theme="huggingface"
51
  )
52
 
53
- # Launch the interface
54
  iface.launch()
 
1
  import gradio as gr
 
 
 
 
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
  import torch
4
  from PIL import Image
 
 
 
 
 
 
 
 
 
5
 
6
+ # Load tokenizer and model
7
  tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-2.7B")
8
  model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neo-2.7B")
9
 
 
 
 
 
 
10
  def generate_image(text):
11
  # Tokenize input text
12
  input_ids = tokenizer.encode(text, return_tensors="pt")
 
24
 
25
  # Create Gradio interface
26
  iface = gr.Interface(
27
+ fn=generate_image,
28
+ inputs=gr.inputs.Textbox(lines=3, label="Input Text"),
29
+ outputs="image",
30
+ title="Text-to-Image Generator",
31
+ description="Generate images from text using Hugging Face's GPT-Neo model.",
32
  theme="huggingface"
33
  )
34
 
35
+ # Launch Gradio interface
36
  iface.launch()