Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
2
+ import torch
3
+ import gradio as gr
4
+
5
+ # Step 1: Define the model name from Hugging Face Hub
6
+ model_name = "deepseek-ai/deepseek-7b-instruct"
7
+
8
+ # Step 2: Load the tokenizer and model
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
10
+ model = AutoModelForCausalLM.from_pretrained(
11
+ model_name,
12
+ torch_dtype=torch.float16, # Use float16 for efficiency
13
+ device_map="auto" # Automatically assigns GPU or CPU
14
+ )
15
+
16
+ # Step 3: Define a simple function to generate model responses
17
+ def chat_function(prompt):
18
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
19
+ outputs = model.generate(**inputs, max_length=300, do_sample=True, temperature=0.7)
20
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
21
+ return response
22
+
23
+ # Step 4: Create the Gradio interface
24
+ iface = gr.Interface(
25
+ fn=chat_function,
26
+ inputs=gr.Textbox(lines=5, placeholder="Type your question here..."),
27
+ outputs="text",
28
+ title="🦾 DeepSeek LLM Assistant",
29
+ description="Ask me anything! Powered by DeepSeek-7B-Instruct 🪐"
30
+ )
31
+
32
+ # Step 5: Launch the app
33
+ if __name__ == "__main__":
34
+ iface.launch()