Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
from unsloth import FastLanguageModel
|
| 4 |
-
import spaces # Ye
|
| 5 |
|
| 6 |
model_id = "anupbth1/Ved-Code-7B"
|
| 7 |
|
| 8 |
-
#
|
| 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 |
-
#
|
| 17 |
-
@spaces.GPU
|
| 18 |
-
def
|
| 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 |
-
|
| 28 |
-
return response
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
gr.ChatInterface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|