Spaces:
Sleeping
Sleeping
| 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) |