Spaces:
Sleeping
Sleeping
Update app.py
Browse files31 unmodified lines3233343536372 unmodified lines40414243444546474849505152535455565758596061622 unmodified lines65666768697031 unmodified lines# 3. Chatbot Yanıt Fonksiyonudef respond(user_input, history):# Kullanıcı girdisini mevcut oturuma ekleyip modelden yanıt alıyoruzchat_session.history.append({"role": "user", "parts": [user_input]})response = chat_session.send_message(user_input)2 unmodified lineschat_session.history.append({"role": "model", "parts": [response.text]})# Gradio için tarihçeyi güncelleme (doğru formatta)history = history or [] # Eğer tarihçe boşsa yeni bir liste oluşturhistory.append({"role": "user", "content": user_input})history.append({"role": "assistant", "content": response.text})return history# 4. Başlangıç Mesajını Eklemek İçin `Chatbot`'u Güncellemeinitial_message = [{"role": "assistant", "content": "Hoş geldiniz! Ben sanal bir diş hekimiyim. Diş sağlığıyla ilgili sorularınızı yanıtlamaktan ve bilgi paylaşmaktan mutluluk duyarım. 😊 Lütfen bana neyle ilgileniyorsunuz, ne hakkında bilgi almak istiyorsunuz söyleyin."}]# 5. Gradio Arayüzü Oluşturmawith gr.Blocks() as demo:chatbot = gr.Chatbot(label="Sanal Diş Hekimi Chatbot", type="messages")# Sohbet geçmişine başlangıç mesajını otomatik olarak ekliyoruzchatbot.value = initial_messagewith gr.Row():user_input = gr.Textbox(show_label=False, placeholder="Bir mesaj yazın ve Enter'a basın...", lines=1)send_button = gr.Button("Gönder")2 unmodified linessend_button.click(fn=respond, inputs=[user_input, chatbot], outputs=[chatbot])user_input.submit(fn=respond, inputs=[user_input, chatbot], outputs=[chatbot])# 6. Uygulamayı Başlatmaif __name__ == "__main__":demo.launch(share=True)31 unmodified lines3233343536373839404142432 unmodified lines46474849505152535455565758592 unmodified lines62636465666731 unmodified lines# 3. Chatbot Yanıt Fonksiyonudef respond(user_input, history):# Tarihçede henüz bir mesaj yoksa, başlangıç mesajını ekleif not history:history = [{"role": "assistant", "content": "Hoş geldiniz! Ben sanal bir diş hekimiyim. Diş sağlığıyla ilgili sorularınızı yanıtlamaktan ve bilgi paylaşmaktan mutluluk duyarım. 😊"}]# Kullanıcı girdisini mevcut oturuma ekleyip modelden yanıt alıyoruzchat_session.history.append({"role": "user", "parts": [user_input]})response = chat_session.send_message(user_input)2 unmodified lineschat_session.history.append({"role": "model", "parts": [response.text]})# Gradio için tarihçeyi güncelleme (doğru formatta)history.append({"role": "user", "content": user_input})history.append({"role": "assistant", "content": response.text})return history# 4. Gradio Arayüzü Oluşturmawith gr.Blocks() as demo:chatbot = gr.Chatbot(label="Sanal Diş Hekimi Chatbot", type="messages")with gr.Row():user_input = gr.Textbox(show_label=False, placeholder="Bir mesaj yazın ve Enter'a basın...", lines=1)send_button = gr.Button("Gönder")2 unmodified linessend_button.click(fn=respond, inputs=[user_input, chatbot], outputs=[chatbot])user_input.submit(fn=respond, inputs=[user_input, chatbot], outputs=[chatbot])# 5. Uygulamayı Başlatmaif __name__ == "__main__":demo.launch(share=True)
app.py+8-11