Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,29 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
| 7 |
-
model =
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
reply = chat(user_input)
|
| 31 |
-
history.append((user_input, reply))
|
| 32 |
-
return history, ""
|
| 33 |
-
|
| 34 |
-
send_btn.click(respond, inputs=[msg, chatbox], outputs=[chatbox, msg])
|
| 35 |
-
|
| 36 |
-
demo.launch()
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
+
# Załaduj model
|
| 5 |
+
model_name = "google/mt5-small"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
# Funkcja odpowiadająca na pytanie
|
| 10 |
+
def answer_question(question):
|
| 11 |
+
input_text = f"Pytanie: {question} Odpowiedź:"
|
| 12 |
+
inputs = tokenizer.encode(input_text, return_tensors="pt")
|
| 13 |
+
output = model.generate(
|
| 14 |
+
inputs,
|
| 15 |
+
max_new_tokens=60,
|
| 16 |
+
do_sample=False,
|
| 17 |
+
temperature=0.3,
|
| 18 |
+
top_p=0.95
|
| 19 |
+
)
|
| 20 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
| 21 |
+
|
| 22 |
+
# Gradio UI
|
| 23 |
+
gr.Interface(
|
| 24 |
+
fn=answer_question,
|
| 25 |
+
inputs=gr.Textbox(lines=2, placeholder="Zadaj pytanie..."),
|
| 26 |
+
outputs=gr.Textbox(),
|
| 27 |
+
title="🤖 Polski Chatbot AI",
|
| 28 |
+
description="Zadaj pytanie po polsku, a chatbot udzieli sensownej odpowiedzi"
|
| 29 |
+
).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|