# -*- coding: utf-8 -*- """Untitled0.ipynb Automatically generated by Colab. Original file is located at https://colab.research.google.com/drive/1kkl1QEIaAfNoIvtzgEzbQIUhuxSI6FIl """ import gradio as gr from transformers import pipeline import re # Assuming 'pipe' is already defined as in the previous code snippet pipe = pipeline("text-generation", model="learningmachineaz/cirtdan-azerbaijani-chatbot") def chat_with_bot(bot_personality, user_input): """ Chats with the bot, considering bot personality and providing accurate answers in Azerbaijani. Args: bot_personality: A string describing the bot's personality (e.g., "helpful", "friendly"). user_input: The user's message. Returns: The bot's response. """ prompt = f"Sən {bot_personality} bir botsan. İstifadəçinin sualına düzgün və ətraflı cavab ver.\nİstifadəçi: {user_input}\nBot:" try: response = pipe(prompt, max_length=200, num_return_sequences=1, num_beams=3, temperature=0.7) match = re.search(r"Bot:\s*(.*?)(?=(İstifadəçi:|[\r\n]*$))", response[0]['generated_text'], re.DOTALL) if match: bot_message = match.group(1).strip() else: bot_message = "Üzr istəyirəm, səni başa düşmədim." return bot_message except: print("An error occurred during the chat with the bot.") return "Üzr istəyirəm, botla söhbət zamanı xəta baş verdi." # Return error message to Gradio iface = gr.Interface( fn=chat_with_bot, inputs=[ gr.Dropdown(["köməkçi", "dostcasına", "ciddi"], label="Bot Şəxsiyyəti"), # Personality options gr.Textbox(lines=2, placeholder="Sualınızı bura yazın...", label="İstifadəçi Girişi"), # User input ], outputs="text", # Bot response output title="Azərbaycanca Söhbət Botu", # Interface title description="Bu bot, suallarınıza Azərbaycan dilində cavab vermək üçün hazırlanmışdır.", # Interface description ) iface.launch(share=True) # Launch the interface and get a shareable link