|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
model_name = "sarvamai/sarvam-2b-v0.5" |
|
pipe = pipeline("text-generation", model=model_name, device=-1) |
|
|
|
|
|
LANGUAGES = ["English", "Bengali", "Gujarati", "Hindi", "Kannada", "Malayalam", "Marathi", "Oriya", "Punjabi", "Tamil", "Telugu"] |
|
|
|
def chatbot(message, history, language): |
|
|
|
prompt = f"Conversation in {language}:\n" |
|
for human, ai in history: |
|
prompt += f"Human: {human}\nAI: {ai}\n" |
|
prompt += f"Human: {message}\nAI:" |
|
|
|
|
|
response = pipe(prompt, max_new_tokens=100, temperature=0.7, repetition_penalty=1.1)[0]['generated_text'] |
|
|
|
|
|
ai_response = response.split("AI:")[-1].strip() |
|
|
|
return ai_response |
|
|
|
|
|
iface = gr.ChatInterface( |
|
chatbot, |
|
additional_inputs=[ |
|
gr.Dropdown(choices=LANGUAGES, label="Select Language", value="English") |
|
], |
|
title="Multilingual Indian Chatbot", |
|
description="Chat in multiple Indian languages using the sarvam-2b model.", |
|
examples=[ |
|
["नमस्ते, आप कैसे हैं?", "Hindi"] |
|
], |
|
theme="soft" |
|
) |
|
|
|
|
|
iface.launch() |
|
|