Spaces:
Runtime error
Runtime error
File size: 2,039 Bytes
2df9f77 a529805 2df9f77 27f1de9 2df9f77 c304acb 2df9f77 9873a98 2df9f77 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# -*- 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 |