import gradio as gr from transformers import AutoTokenizer, AutoModelForCausalLM # Load DeepSeek-R1 model model_name = "deepseek-ai/DeepSeek-R1" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForCausalLM.from_pretrained(model_name) # Chat function def chat_with_ai(prompt): inputs = tokenizer(prompt, return_tensors="pt") outputs = model.generate(**inputs, max_new_tokens=250) response = tokenizer.decode(outputs[0], skip_special_tokens=True) return response # Gradio UI ui = gr.Interface( fn=chat_with_ai, inputs=gr.Textbox(label="Ask me anything..."), outputs="text", title="💬 DeepSeek-R1 AI", description="Chat with your own DeepSeek-R1 model hosted on Hugging Face Cloud!" ) ui.launch()