anupbth1 commited on
Commit
5a1400a
·
verified ·
1 Parent(s): 190268c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -1,11 +1,11 @@
1
  import gradio as gr
2
  import torch
3
  from unsloth import FastLanguageModel
4
- import spaces # Ye line ZeroGPU ke liye zaroori hai
5
 
6
  model_id = "anupbth1/Ved-Code-7B"
7
 
8
- # 1. Model loading (Global)
9
  model, tokenizer = FastLanguageModel.from_pretrained(
10
  model_name = model_id,
11
  max_seq_length = 2048,
@@ -13,19 +13,22 @@ model, tokenizer = FastLanguageModel.from_pretrained(
13
  )
14
  FastLanguageModel.for_inference(model)
15
 
16
- # 2. GPU Function
17
- @spaces.GPU # Ye decorator model ko GPU power deta hai
18
- def generate_code(message, history):
19
  messages = [{"role": "user", "content": message}]
20
  inputs = tokenizer.apply_chat_template(
21
  messages,
22
  add_generation_prompt = True,
23
  return_tensors = "pt"
24
- ).to("cuda") # Force to CUDA
25
 
26
  outputs = model.generate(**inputs, max_new_tokens=512)
27
- response = tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True)
28
- return response
29
 
30
- # 3. Chat Interface
31
- gr.ChatInterface(generate_code).launch()
 
 
 
 
 
1
  import gradio as gr
2
  import torch
3
  from unsloth import FastLanguageModel
4
+ import spaces # Ye ZeroGPU ke liye zaroori hai
5
 
6
  model_id = "anupbth1/Ved-Code-7B"
7
 
8
+ # Model ko 4-bit mein load karna (RAM bachane ke liye)
9
  model, tokenizer = FastLanguageModel.from_pretrained(
10
  model_name = model_id,
11
  max_seq_length = 2048,
 
13
  )
14
  FastLanguageModel.for_inference(model)
15
 
16
+ # ZeroGPU access ke liye decorator
17
+ @spaces.GPU(duration=60)
18
+ def generate(message, history):
19
  messages = [{"role": "user", "content": message}]
20
  inputs = tokenizer.apply_chat_template(
21
  messages,
22
  add_generation_prompt = True,
23
  return_tensors = "pt"
24
+ ).to("cuda")
25
 
26
  outputs = model.generate(**inputs, max_new_tokens=512)
27
+ return tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True)
 
28
 
29
+ # UI Layout
30
+ gr.ChatInterface(
31
+ generate,
32
+ title="Ved-Code-7B 🚀",
33
+ description="Custom Coding Assistant by anupbth1"
34
+ ).launch()