File size: 3,212 Bytes
7962c79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import gradio as gr
import os
from utils import process_pipeline

# Define the UI
with gr.Blocks(theme=gr.themes.Soft()) as demo:
    
    # Header
    with gr.Row():
        gr.Markdown(
            """
            # 🇹🇭 Thai to AI Media Generator
            ### แปลงข้อความไทยเป็นภาพและเสียงด้วย AI (Translate Thai -> Image & Audio)
            [Built with anycoder](https://huggingface.co/spaces/akhaliq/anycoder)
            """
        )

    with gr.Row():
        with gr.Column(scale=1):
            # Input Section
            input_text = gr.Textbox(
                label="ใส่ข้อความภาษาไทย (Input Thai Text)",
                placeholder="ตัวอย่าง: แมวน่ารักใส่แว่นกันแดดนั่งอยู่บนชายหาด",
                lines=3
            )
            
            style_dropdown = gr.Dropdown(
                choices=["None", "Cinematic", "Anime", "3D Model", "Oil Painting", "Pixel Art"],
                value="None",
                label="สไตล์ภาพ (Image Style)"
            )
            
            submit_btn = gr.Button("✨ สร้างผลงาน (Generate)", variant="primary", size="lg")
            
            gr.Markdown(
                """
                **หมายเหตุ:** 
                - ระบบจะใช้โมเดลฟรีบน Hugging Face
                - การประมวลผลอาจใช้เวลา 10-30 วินาทีขึ้นอยู่กับความหนาแน่นของ Server
                """
            )

        with gr.Column(scale=1):
            # Output Section
            with gr.Group():
                gr.Markdown("### 1. ผลลัพธ์การแปล (Translation)")
                output_translation = gr.Textbox(label="English Translation", interactive=False)
            
            with gr.Group():
                gr.Markdown("### 2. ภาพที่สร้างได้ (Generated Image)")
                output_image = gr.Image(label="AI Image", type="pil")
            
            with gr.Group():
                gr.Markdown("### 3. เสียงบรรยาย (Generated Audio)")
                output_audio = gr.Audio(label="AI Speech", type="filepath")

    # Logic Connection
    submit_btn.click(
        fn=process_pipeline,
        inputs=[input_text, style_dropdown],
        outputs=[output_translation, output_image, output_audio]
    )
    
    # Add examples
    gr.Examples(
        examples=[
            ["เด็กผู้หญิงใส่ชุดไทยยืนอยู่หน้าวัดอรุณ", "Cinematic"],
            ["หุ่นยนต์แห่งโลกอนาคตกำลังทำอาหารในครัว", "3D Model"],
            ["ป่ามหัศจรรย์ที่มีต้นไม้เรืองแสง", "Oil Painting"]
        ],
        inputs=[input_text, style_dropdown]
    )

if __name__ == "__main__":
    demo.launch()