| from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| import torch
|
| import gradio as gr
|
|
|
|
|
| model_name = "deepseek-ai/deepseek-7b-instruct"
|
|
|
|
|
| tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| model = AutoModelForCausalLM.from_pretrained(
|
| model_name,
|
| torch_dtype=torch.float16,
|
| device_map="auto"
|
| )
|
|
|
|
|
| def chat_function(prompt):
|
| inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| outputs = model.generate(**inputs, max_length=300, do_sample=True, temperature=0.7)
|
| response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| return response
|
|
|
|
|
| iface = gr.Interface(
|
| fn=chat_function,
|
| inputs=gr.Textbox(lines=5, placeholder="Type your question here..."),
|
| outputs="text",
|
| title="🦾 DeepSeek LLM Assistant",
|
| description="Ask me anything! Powered by DeepSeek-7B-Instruct 🪐"
|
| )
|
|
|
|
|
| if __name__ == "__main__":
|
| iface.launch()
|
|
|