Inan Ince
commited on
Commit
·
5ecd486
1
Parent(s):
942ac8f
Add application file9
Browse files
app.py
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# Modeli yükle
|
| 5 |
+
chatbot_model = pipeline("text2text-generation", model="facebook/blenderbot-400M-distill")
|
| 6 |
+
|
| 7 |
+
# Chatbot için mesaj işleme fonksiyonu
|
| 8 |
+
def inan_ai_chatbot(message, history):
|
| 9 |
+
response = chatbot_model(message)
|
| 10 |
+
return response[0]["generated_text"]
|
| 11 |
+
|
| 12 |
+
# Özelleştirilmiş Gradio arayüzü
|
| 13 |
+
with gr.Blocks(theme="compact") as demo:
|
| 14 |
+
gr.Markdown("<h1 style='text-align: center; color: #4CAF50;'>İnan AI</h1>")
|
| 15 |
+
gr.Markdown("<p style='text-align: center;'>Sohbet etmeye başlamak için aşağıdaki kutuya bir mesaj yazabilirsiniz.</p>")
|
| 16 |
+
|
| 17 |
+
chatbot = gr.Chatbot(label="İnan AI Sohbet Ekranı")
|
| 18 |
+
with gr.Row():
|
| 19 |
+
msg = gr.Textbox(label="Mesajınızı yazın:", placeholder="Bir şeyler yazın...")
|
| 20 |
+
send_btn = gr.Button("Gönder")
|
| 21 |
+
|
| 22 |
+
def update_ui(message, chat_history):
|
| 23 |
+
# Kullanıcı mesajını ekle
|
| 24 |
+
chat_history = chat_history + [(message, "")]
|
| 25 |
+
response = inan_ai_chatbot(message, chat_history)
|
| 26 |
+
# Modelin yanıtını ekle
|
| 27 |
+
chat_history[-1] = (message, response)
|
| 28 |
+
return chat_history, ""
|
| 29 |
+
|
| 30 |
+
msg.submit(update_ui, [msg, chatbot], [chatbot, msg])
|
| 31 |
+
send_btn.click(update_ui, [msg, chatbot], [chatbot, msg])
|
| 32 |
+
|
| 33 |
+
# Uygulamayı başlat
|
| 34 |
+
demo.launch()
|