|
|
|
|
|
from openai import OpenAI |
|
|
import gradio as gr |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client=OpenAI() |
|
|
|
|
|
|
|
|
rules = [ |
|
|
"U偶ywaj kr贸tkich zda艅", |
|
|
"Unikaj trudnych s艂贸w", |
|
|
"Stosuj proste konstrukcje gramatyczne", |
|
|
"Unikaj 偶argonu i skr贸t贸w", |
|
|
"Stosuj aktywn膮 stron臋" |
|
|
] |
|
|
|
|
|
def generate_response(prompt, selected_rules=None): |
|
|
if selected_rules is None: |
|
|
selected_rules = rules |
|
|
|
|
|
|
|
|
rules_text = "\n".join([f"- {rule}" for rule in selected_rules]) |
|
|
|
|
|
|
|
|
full_prompt = f"""Upro艣膰 poni偶szy tekst zgodnie z zasadami prostego j臋zyka: |
|
|
{rules_text} |
|
|
|
|
|
Tekst: |
|
|
{prompt}""" |
|
|
|
|
|
response = client.chat.completions.create( |
|
|
model="gpt-4.1", |
|
|
messages=[ |
|
|
{"role": "system", "content": "Jeste艣 pomocnym asystentem upraszczaj膮cym teksty."}, |
|
|
{"role": "user", "content": full_prompt} |
|
|
], |
|
|
temperature=0.1, |
|
|
) |
|
|
return response.choices[0].message.content |
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown("# Uproszczenie Tekstu") |
|
|
gr.Markdown("Wprowad藕 tekst, kt贸ry chcesz upro艣ci膰. Model AI upro艣ci go, aby by艂 bardziej zrozumia艂y.") |
|
|
|
|
|
with gr.Accordion("Regu艂y prostego j臋zyka", open=False): |
|
|
rules_checkboxes = gr.CheckboxGroup( |
|
|
choices=rules, |
|
|
value=rules, |
|
|
label="Zastosuj regu艂y" |
|
|
) |
|
|
|
|
|
input_text = gr.TextArea(label="Tekst do uproszczenia") |
|
|
output_text = gr.TextArea(label="Uproszczony Tekst") |
|
|
|
|
|
submit_button = gr.Button("Upro艣膰 tekst") |
|
|
submit_button.click( |
|
|
generate_response, |
|
|
inputs=[input_text, rules_checkboxes], |
|
|
outputs=output_text |
|
|
) |
|
|
|
|
|
demo.launch(inbrowser=True) |
|
|
|
|
|
|
|
|
|