PunishingPoison commited on
Commit
8e290c1
·
verified ·
1 Parent(s): 9c4051c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+
5
+ # Load DeepSeek-Coder-7B Model
6
+ MODEL_NAME = "deepseek-ai/deepseek-coder-7b-instruct"
7
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
8
+ model = AutoModelForCausalLM.from_pretrained(
9
+ MODEL_NAME,
10
+ torch_dtype=torch.float16,
11
+ device_map="auto"
12
+ )
13
+
14
+ # System Prompt to Guide the Model
15
+ SYSTEM_PROMPT = """
16
+ You are a highly skilled AI specialized in programming and mathematics.
17
+ - For coding questions, provide clear explanations and format code inside triple backticks.
18
+ - For math problems, explain step-by-step solutions neatly.
19
+ - Keep responses professional, concise, and well-structured.
20
+ """
21
+
22
+ def generate_response(prompt):
23
+ formatted_prompt = f"{SYSTEM_PROMPT}\n\nUser: {prompt}\nAI:" # Injecting system instructions
24
+ inputs = tokenizer(formatted_prompt, return_tensors="pt").to("cuda")
25
+ outputs = model.generate(inputs["input_ids"], max_length=700)
26
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
27
+
28
+ return response
29
+
30
+ # Create Gradio Interface
31
+ interface = gr.Interface(
32
+ fn=generate_response,
33
+ inputs=gr.Textbox(lines=5, placeholder="Enter your math or coding question here..."),
34
+ outputs="text",
35
+ title="DeepSeek Coder & Math Pro",
36
+ description="Ask anything about programming or mathematics!",
37
+ theme="default",
38
+ )
39
+
40
+ interface.launch()