File size: 1,653 Bytes
0e874fd
 
e6ac8c7
45dfcb6
0e874fd
 
45dfcb6
e6ac8c7
0e874fd
 
 
45dfcb6
0e874fd
 
9daea58
c1a6a26
9daea58
 
0e874fd
9daea58
0e874fd
 
9daea58
45dfcb6
9daea58
 
 
 
 
 
 
 
0e874fd
9daea58
 
 
 
 
 
0e874fd
 
788d3cd
 
 
 
 
78a2c3f
53fec9e
78a2c3f
 
53fec9e
 
 
 
 
788d3cd
ffb5afc
788d3cd
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import requests
import gradio as gr
from dotenv import load_dotenv  
import io
from PIL import Image
from mtranslate import translate  

load_dotenv()

api_key = os.getenv("HF_API_KEY")
image_api_url = os.getenv("model") 
headers = {"Authorization": f"Bearer {api_key}"}

censored_words = [
    "sex", "porn", "asshole", "fuck", "cock", "pussy", "dick", "cum","nude", "naked", "fetish"
]

def query(payload):
    response = requests.post(image_api_url, headers=headers, json=payload)
    return response.content

def translate_to_english(text):
    return translate(text, "en", "vi")  

def contains_censored_words(text):
    text = text.lower()
    for word in censored_words:
        if word in text:
            return True
    return False

def generate_image(prompt):
    prompt_en = translate_to_english(prompt)
    
    if contains_censored_words(prompt_en):
        return "Mô tả chứa từ cấm, vui lòng thử lại với mô tả khác."
    
    image_bytes = query({"inputs": prompt_en})
    image = Image.open(io.BytesIO(image_bytes))
    return image

iface = gr.Interface(
    fn=generate_image,
    inputs="text",
    outputs="image",
    title="Tạo sinh hình ảnh | 0379031662",
    description = """
    # Từ ý tưởng ra hình ảnh  
    **Lưu ý:** Hãy sử dụng từ ngữ đơn giản, có thể gõ bằng Tiếng Việt.  
    **Tác giả:** Như Tuấn  
    **Instagram:** [dk.darkkool](https://instagram.com/dk.darkkool)  
    **Facebook:** [darkkool](https://facebook.com/darkkool)  
    **Website:** [kooldstudio.pixieset.com](https://kooldstudio.pixieset.com)  
    """    
)

iface.launch()