Spaces:
Sleeping
Sleeping
Pierwsza wersja
Browse files
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from openai import OpenAI
|
3 |
+
|
4 |
+
client = OpenAI()
|
5 |
+
|
6 |
+
def simplify_text(text):
|
7 |
+
if not text:
|
8 |
+
return "", "0 token贸w", "0 token贸w"
|
9 |
+
|
10 |
+
response = client.chat.completions.create(
|
11 |
+
model="gpt-4o-mini",
|
12 |
+
messages=[
|
13 |
+
{"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."},
|
14 |
+
{"role": "user", "content": f"Upro艣膰 ten tekst:\n{text}"}
|
15 |
+
],
|
16 |
+
temperature=0.7
|
17 |
+
)
|
18 |
+
|
19 |
+
simplified_text = response.choices[0].message.content
|
20 |
+
input_tokens = response.usage.prompt_tokens
|
21 |
+
output_tokens = response.usage.completion_tokens
|
22 |
+
|
23 |
+
return (
|
24 |
+
simplified_text,
|
25 |
+
f"{input_tokens} token贸w",
|
26 |
+
f"{output_tokens} token贸w"
|
27 |
+
)
|
28 |
+
|
29 |
+
with gr.Blocks() as demo:
|
30 |
+
gr.Markdown("# Prostownik - narz臋dzie do upraszczania tekst贸w")
|
31 |
+
|
32 |
+
with gr.Row():
|
33 |
+
with gr.Column():
|
34 |
+
input_area = gr.TextArea(
|
35 |
+
label="Tekst wej艣ciowy",
|
36 |
+
placeholder="Wklej tutaj tekst do uproszczenia...",
|
37 |
+
lines=10
|
38 |
+
)
|
39 |
+
input_tokens = gr.Textbox(label="Liczba token贸w wej艣ciowych")
|
40 |
+
|
41 |
+
with gr.Column():
|
42 |
+
output_area = gr.TextArea(
|
43 |
+
label="Tekst uproszczony",
|
44 |
+
lines=10,
|
45 |
+
show_copy_button=True
|
46 |
+
)
|
47 |
+
output_tokens = gr.Textbox(label="Liczba token贸w wyj艣ciowych")
|
48 |
+
|
49 |
+
input_area.change(
|
50 |
+
fn=simplify_text,
|
51 |
+
inputs=input_area,
|
52 |
+
outputs=[output_area, input_tokens, output_tokens]
|
53 |
+
)
|
54 |
+
|
55 |
+
demo.launch()
|