Spaces:
Sleeping
Sleeping
File size: 1,373 Bytes
fccd3f3 a39566b fccd3f3 a39566b fccd3f3 0351e82 fccd3f3 0351e82 fccd3f3 |
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 |
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
import spaces
model_name = "MBZUAI-Paris/Atlas-Chat-27B"
dtype = torch.bfloat16
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=dtype,
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
@spaces.GPU
def chat(input_text, history=[]):
# Tokenize the input and generate response
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=150)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
# Update the conversation history
history.append((input_text, response))
return history, history
iface = gr.Interface(
fn=chat,
inputs=[
gr.Textbox(label="أدخل رسالتك هنا"),
gr.State()
],
outputs=[
gr.Chatbot(label="المحادثة"),
gr.State()
],
live=True,
title="دردشة أطلس",
description="تطبيق دردشة يعمل بنموذج أطلس-شات لتوفير تفاعل ذكي وسلس",
theme="huggingface",
examples=[
["مرحباً! كيف يمكنني مساعدتك اليوم؟"],
["ما هي أخبار التكنولوجيا الحديثة؟"]
]
)
# Launch the application
iface.launch()
|