Atlas-Chat / app.py
yasserrmd's picture
Create app.py
fccd3f3 verified
raw
history blame
1.36 kB
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
import spaces
model_name = "MBZUAI-Paris/Atlas-Chat-27B"
model = AutoModelForCausalLM.from_pretrained(
model_name,
load_in_4bit=True,
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.inputs.Textbox(label="ุฃุฏุฎู„ ุฑุณุงู„ุชูƒ ู‡ู†ุง"),
"state"
],
outputs=[
gr.outputs.Chatbot(label="ุงู„ู…ุญุงุฏุซุฉ"),
"state"
],
live=True,
title="ุฏุฑุฏุดุฉ ุฃุทู„ุณ",
description="ุชุทุจูŠู‚ ุฏุฑุฏุดุฉ ูŠุนู…ู„ ุจู†ู…ูˆุฐุฌ ุฃุทู„ุณ-ุดุงุช ู„ุชูˆููŠุฑ ุชูุงุนู„ ุฐูƒูŠ ูˆุณู„ุณ",
theme="huggingface",
examples=[
["ู…ุฑุญุจุงู‹! ูƒูŠู ูŠู…ูƒู†ู†ูŠ ู…ุณุงุนุฏุชูƒ ุงู„ูŠูˆู…ุŸ"],
["ู…ุง ู‡ูŠ ุฃุฎุจุงุฑ ุงู„ุชูƒู†ูˆู„ูˆุฌูŠุง ุงู„ุญุฏูŠุซุฉุŸ"]
]
)
# Launch the application
iface.launch()