File size: 1,081 Bytes
1c2ed85
 
26043fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import gradio as gr
import torch
from transformers import AutoTokenizer, AutoModel
import matplotlib.pyplot as plt

# Model ve tokenizer'ı yükleyin
model_name = "your-username/apolar.safesensor"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModel.from_pretrained(model_name)

def generate_image(prompt):
    # Giriş metnini tokenlara çevirin
    inputs = tokenizer(prompt, return_tensors="pt")

    # Modeli kullanarak görüntü üretin
    with torch.no_grad():
        outputs = model(**inputs)

    # Çıktıyı işleyin (bu örnek genel bir kullanım içindir, kendi modelinize göre ayarlayın)
    image_tensor = outputs[0]

    # Görüntüyü matplotlib ile kaydedin
    plt.imshow(image_tensor.permute(1, 2, 0).cpu().numpy())
    plt.axis('off')  # Ekseni kapat
    plt.savefig("output.png")

    return "output.png"

# Gradio arayüzünü oluşturun
iface = gr.Interface(
    fn=generate_image,
    inputs="text",
    outputs="image",
    title="Text to Image Generation",
    description="Enter a prompt to generate an image"
)

iface.launch()