Samuel4677 commited on
Commit
575322f
·
verified ·
1 Parent(s): d02d07c
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Ładowanie modelu raz
5
+ chatbot = pipeline("text-generation", model="radlab/polish-gpt2-small", max_new_tokens=80)
6
+
7
+ # Historia rozmowy
8
+ conversation_history = ""
9
+
10
+ def respond(user_input, history):
11
+ global conversation_history
12
+ conversation_history += f"Użytkownik: {user_input}\nAI: "
13
+
14
+ response = chatbot(conversation_history, do_sample=True, top_k=50, top_p=0.95, temperature=0.7)[0]["generated_text"]
15
+ ai_response = response[len(conversation_history):].split("Użytkownik:")[0].strip()
16
+
17
+ conversation_history += ai_response + "\n"
18
+ return conversation_history, conversation_history
19
+
20
+ def clear_history():
21
+ global conversation_history
22
+ conversation_history = ""
23
+ return "", ""
24
+
25
+ # UI
26
+ with gr.Blocks() as demo:
27
+ gr.Markdown("# 🤖 Polski Chatbot AI\nNapisz coś po polsku, a AI odpowie!")
28
+
29
+ chatbox = gr.Textbox(label="Twoja wiadomość")
30
+ history_box = gr.Textbox(label="📖 Historia rozmowy", lines=10)
31
+
32
+ submit_btn = gr.Button("Wyślij")
33
+ clear_btn = gr.Button("🧹 Wyczyść")
34
+
35
+ submit_btn.click(fn=respond, inputs=[chatbox, history_box], outputs=[history_box, history_box])
36
+ clear_btn.click(fn=clear_history, outputs=[history_box, history_box])
37
+
38
+ demo.launch()