File size: 1,776 Bytes
423e87c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49890f6
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
import gradio as gr
from openai import OpenAI

client = OpenAI()

def simplify_text(text):
    if not text:
        return "", "0 token贸w", "0 token贸w"
    
    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[
            {"role": "system", "content": "Jeste艣 ekspertem w upraszczaniu tekst贸w. Twoim zadaniem jest uproszczenie podanego tekstu, zachowuj膮c jego g艂贸wne znaczenie, ale u偶ywaj膮c prostszego j臋zyka. Nie formatuj tekstu za pomoc膮 znacznik贸w Markdown."},
            {"role": "user", "content": f"Upro艣膰 ten tekst:\n{text}"}
        ],
        temperature=0.7
    )
    
    simplified_text = response.choices[0].message.content
    input_tokens = response.usage.prompt_tokens
    output_tokens = response.usage.completion_tokens
    
    return (
        simplified_text,
        f"{input_tokens} token贸w",
        f"{output_tokens} token贸w"
    )

with gr.Blocks() as demo:
    gr.Markdown("# Prostownik - narz臋dzie do upraszczania tekst贸w")
    
    with gr.Row():
        with gr.Column():
            input_area = gr.TextArea(
                label="Tekst wej艣ciowy",
                placeholder="Wklej tutaj tekst do uproszczenia...",
                lines=10
            )
            input_tokens = gr.Textbox(label="Liczba token贸w wej艣ciowych")
            
        with gr.Column():
            output_area = gr.TextArea(
                label="Tekst uproszczony",
                lines=10,
                show_copy_button=True
            )
            output_tokens = gr.Textbox(label="Liczba token贸w wyj艣ciowych")
    
    input_area.change(
        fn=simplify_text,
        inputs=input_area,
        outputs=[output_area, input_tokens, output_tokens]
    )

    demo.launch(share=True)