Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import AutoModelForCausalLM, AutoTokenizer | |
# Load model and tokenizer | |
model_name = "deepseek-ai/DeepSeek-V3" | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True) | |
# Function to handle chatbot response | |
def chat_with_deepseek(prompt): | |
inputs = tokenizer(prompt, return_tensors="pt") | |
outputs = model.generate( | |
inputs["input_ids"], | |
max_length=512, | |
num_return_sequences=1, | |
pad_token_id=tokenizer.eos_token_id | |
) | |
response = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
return response | |
# Gradio interface | |
with gr.Blocks() as demo: | |
gr.Markdown("# DeepSeek Chatbot") | |
with gr.Row(): | |
with gr.Column(): | |
user_input = gr.Textbox(label="Enter your message", placeholder="Type something...") | |
with gr.Column(): | |
submit_btn = gr.Button("Send") | |
chatbot_output = gr.Textbox(label="Response", placeholder="Chatbot response will appear here") | |
submit_btn.click(chat_with_deepseek, inputs=user_input, outputs=chatbot_output) | |
demo.launch() | |