File size: 5,986 Bytes
12c887a
d90acf0
 
 
 
c89e6c8
 
d90acf0
12c887a
d90acf0
 
12c887a
e05546f
d90acf0
 
 
 
 
 
 
 
 
 
 
 
 
 
e05546f
 
 
 
 
 
a963159
e05546f
 
d90acf0
 
cab6c41
c89e6c8
d90acf0
 
9407c61
d90acf0
 
6e75167
 
d90acf0
 
 
 
 
 
 
 
b8cc2cc
 
 
103cb97
 
 
 
b8cc2cc
 
103cb97
 
 
 
 
 
b8cc2cc
 
103cb97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d90acf0
 
 
 
 
 
 
 
 
e09b6d2
 
47d75db
e09b6d2
 
d90acf0
 
2b6bf66
d90acf0
521407c
 
0d1b52c
521407c
 
 
 
6e75167
0d1b52c
 
 
 
 
 
 
 
 
 
 
d90acf0
 
 
 
 
 
 
 
 
 
 
 
 
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import gradio as gr
import time
from src.constructor import generate_presentation 
from src.prompt_configs import en_gigachat_config, ru_gigachat_config
from src.gigachat import giga_generate
# from src.kandinsky import api_k31_generate
from src.kandinsky import generate_image
from src.font import Font

logs_dir = "logs"
fonts_dir = "fonts"

def create_presentation(description: str, slides_num: int, language: str, num_inference_steps: int, image_res: str):
    # Select the appropriate prompt configuration based on the selected language
    if language == "English":
        prompt_config = en_gigachat_config
    elif language == "Русский":
        prompt_config = ru_gigachat_config
    else: 
        # set default to prevent interruptions in unexpected scenario
        prompt_config = en_gigachat_config
        
    font = Font(fonts_dir)
    font.set_random_font() 
    
    output_dir = f'{logs_dir}/{int(time.time())}'

    if image_res == "192x336 & 256x256":
        image_size_coef = 0.25
    elif image_res == "384x672 & 512x512":
        image_size_coef = 0.5
    elif image_res == "576x1008 & 768x768":
        image_size_coef = 0.75
    else:
        image_size_coef = 1.0
    
    generate_presentation(
        llm_generate=giga_generate, 
        # generate_image=api_k31_generate,
        generate_image=generate_image,
        prompt_config=prompt_config, 
        description=description,
        slides_num=slides_num,
        font=font,
        output_dir=output_dir,
        num_inference_steps=num_inference_steps,
        image_size_coef=image_size_coef
    )

    filename = f'{output_dir}/presentation.pptx'
    
    return filename

# Updated examples to include language selection
examples = [

    ["How to explain to a cat that he is not in charge of the house: a study of owners", 6, "English"],
    ["Как объяснить коту, что он не главный в доме: исследование владельцев", 6, "Русский"],
    ["Basic concepts of economics", 7, "English"],
    ["Базовые понятия экономики", 7, "Русский"],
    ["Climate change", 6, "English"],
    ["Изменение климата", 6, "Русский"],
    ["The Secret Life of an Office Printer: Why It Prints when You're Not Looking", 6, "English"],
    ["Тайная жизнь офисного принтера: почему он печатает, когда ты не смотришь", 6, "Русский"],
    ["Artificial intelligence", 5, "English"],
    ["Искусственный интеллект", 5, "Русский"],
    ["Space exploration", 7, "English"],
    ["Космические исследования", 7, "Русский"],
    ["The future of renewable energy", 7, "English"],
    ["Будущее возобновляемой энергетики", 7, "Русский"],
    ["5 ways to understand that you are in IT, so that the slides are about bugs and caffeine", 6, "English"],
    ["5 способов понять, что ты в IT, чтобы в слайдах было про баги и кофеин", 6, "Русский"],
    ["The history of art movements", 6, "English"],
    ["История художественных движений", 6, "Русский"],
    ["The impact of social media", 6, "English"],
    ["Влияние социальных сетей", 6, "Русский"],
    ["Sustainable urban planning", 7, "English"],
    ["Устойчивое градостроительство", 7, "Русский"],
    ["Новшества в области медицинских технологий", 7, "Русский"],
    ["Innovations in healthcare technology", 7, "English"],
    ["Глобальные экономические тенденции", 5, "Русский"],
    ["Global economic trends", 5, "English"],
    ["Психология потребительского поведения", 6, "Русский"],
    ["The psychology of consumer behavior", 6, "English"],
    ["Преимущества осознанности и медитации", 7, "Русский"],
    ["The benefits of mindfulness and meditation", 7, "English"],
    ["Достижения в области автономных транспортных средств", 7, "Русский"],
    ["Advancements in autonomous vehicles", 7, "English"],
    ["Влияние изменений климатической политики", 5, "Русский"],
    ["The impact of climate policy changes", 5, "English"],
]

iface = gr.Interface(
    fn=create_presentation,
    inputs=[
        gr.Textbox(
            label="Presentation Description", 
            placeholder="Enter the description for the presentation..."
        ),
        gr.Dropdown(
            label="Number of slides",
            choices=range(1, 8),
            value=5
        ),
        gr.Dropdown(
            label="Language",
            choices=["English", "Русский"],
            value="English"
        ),
        gr.Slider(
            label="Number of diffusion steps",
            minimum=2,
            maximum=50,
            step=1,
            value=50, 
        ),
        # gr.Slider(
        #     label="scaling factor for image reduction",
        #     minimum=0.25,
        #     maximum=1.0,
        #     step=0.05,
        #     value=1.0, 
        # )
        gr.Dropdown(
            label="Image resolution",
            choices=["192x336 & 256x256", "384x672 & 512x512", "576x1008 & 768x768", "768x1344 & 1024x1024"],
            value="768x1344 & 1024x1024"
        )
    ],
    outputs=gr.File(
        label="Download Presentation"
    ),
    title="Presentation Generator",
    description="Generate a presentation based on the provided description and selected language. Click the button to download the presentation.",
    css="footer {visibility: hidden}",
    allow_flagging="never",  
    examples=examples  
)

iface.launch()