Spaces:
Runtime error
Runtime error
Create BTroyUI.py
Browse files- BTroyUI.py +26 -0
BTroyUI.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
| 3 |
+
|
| 4 |
+
# মডেল এবং টোকেনাইজার লোড করুন
|
| 5 |
+
model_name = "mistralai/Pixtral-12B-Base-2409"
|
| 6 |
+
model = GPT2LMHeadModel.from_pretrained(model_name)
|
| 7 |
+
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
# BTroy চ্যাটবটের ফাংশন
|
| 10 |
+
def btroy_chat(input_text):
|
| 11 |
+
inputs = tokenizer.encode(input_text, return_tensors='pt')
|
| 12 |
+
outputs = model.generate(inputs, max_length=200)
|
| 13 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 14 |
+
return response
|
| 15 |
+
|
| 16 |
+
# Gradio ইন্টারফেস তৈরি
|
| 17 |
+
iface = gr.Interface(fn=btroy_chat,
|
| 18 |
+
inputs=gr.Textbox(label="আপনার প্রশ্ন দিন", placeholder="আপনার প্রশ্ন এখানে টাইপ করুন..."),
|
| 19 |
+
outputs="text",
|
| 20 |
+
title="BTroy AI চ্যাটবট",
|
| 21 |
+
description="BTroy চ্যাটবট ব্যবহার করুন আপনার যেকোনো প্রশ্নের উত্তর পেতে।",
|
| 22 |
+
theme="huggingface",
|
| 23 |
+
allow_flagging="never")
|
| 24 |
+
|
| 25 |
+
# ইন্টারফেস রান করুন
|
| 26 |
+
iface.launch()
|