Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
4 |
+
|
5 |
+
MODEL_NAME = "cloudqi/cqi_text_to_image_pt_v0"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
8 |
+
|
9 |
+
def generate_images(description):
|
10 |
+
input_ids = tokenizer.encode(description, return_tensors="pt")
|
11 |
+
# Model generates a batch of one image
|
12 |
+
output = model.generate(input_ids)
|
13 |
+
output_image = output[0].numpy().transpose(1,2,0)
|
14 |
+
return output_image.astype("uint8")
|
15 |
+
|
16 |
+
inputs = gr.inputs.Textbox(prompt="Enter Text Description")
|
17 |
+
outputs = gr.outputs.Image(label="Generated Image")
|
18 |
+
|
19 |
+
iface = gr.Interface(fn=generate_images, inputs=inputs, outputs=outputs, title="Description to Image")
|
20 |
+
iface.disable_caching=True # Disable caching to ensure the model is reloaded each time the app is opened
|
21 |
+
|
22 |
+
if __name__ == "__main__":
|
23 |
+
iface.launch()
|