Spaces:
Sleeping
Sleeping
File size: 1,177 Bytes
04fcb3b 6d4c39c 04fcb3b c64f60a 04fcb3b |
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 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
# Load model and tokenizer
model_name = "Smilyai-labs/Sam-reason-v3"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
# Chat function
def respond(message, history):
history = history or []
chat_prompt = ""
for user, bot in history:
chat_prompt += f"User: {user}\nSam: {bot}\n"
chat_prompt += f"User: {message}\nSam:"
# Tokenize input and generate a response
inputs = tokenizer(chat_prompt, return_tensors="pt")
outputs = model.generate(inputs["input_ids"], max_length=200, num_return_sequences=1)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
reply = response[len(chat_prompt):].split("\n")[0].strip()
history.append((message, reply))
return history, history
# Gradio interface
chatbot = gr.Chatbot()
demo = gr.Interface(
fn=respond,
inputs=[gr.Textbox(label="Your message"), gr.State()],
outputs=[chatbot, gr.State()],
title="🧠 Sam Chatbot",
description="A demo of Sam-large-v1-speacil: chaotic, aligned, and fun."
)
demo.launch()
|