Spaces:
Sleeping
Sleeping
Ahmetahmat
commited on
app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
|
4 |
+
# Model ve tokenizer yükle
|
5 |
+
model_name = "microsoft/DialoGPT-medium"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# Sohbet fonksiyonu
|
10 |
+
def chat_with_bot(input_text, chat_history=[]):
|
11 |
+
# Kullanıcı girdisini encode et
|
12 |
+
new_input_ids = tokenizer.encode(input_text + tokenizer.eos_token, return_tensors="pt")
|
13 |
+
bot_output = model.generate(
|
14 |
+
new_input_ids if not chat_history else torch.cat([chat_history, new_input_ids], dim=-1),
|
15 |
+
max_length=1000,
|
16 |
+
pad_token_id=tokenizer.eos_token_id,
|
17 |
+
)
|
18 |
+
# Botun yanıtını çöz
|
19 |
+
response = tokenizer.decode(bot_output[:, new_input_ids.shape[-1]:][0], skip_special_tokens=True)
|
20 |
+
chat_history.append((input_text, response))
|
21 |
+
return response, chat_history
|
22 |
+
|
23 |
+
# Gradio arayüzü
|
24 |
+
interface = gr.Interface(
|
25 |
+
fn=chat_with_bot,
|
26 |
+
inputs=["text", "state"],
|
27 |
+
outputs=["text", "state"],
|
28 |
+
live=True,
|
29 |
+
title="Sohbet Botu",
|
30 |
+
description="Bir chatbot ile konuşmaya başlayın!",
|
31 |
+
)
|
32 |
+
|
33 |
+
interface.launch()
|