Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,48 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 3 |
-
from peft import PeftModel, PeftConfig
|
| 4 |
-
import gradio as gr
|
| 5 |
-
|
| 6 |
-
PEFT_MODEL_ID = "rishu834763/java-explainer-lora"
|
| 7 |
-
|
| 8 |
-
config = PeftConfig.from_pretrained(PEFT_MODEL_ID)
|
| 9 |
-
base_model_name = config.base_model_name_or_path
|
| 10 |
-
print(f"Loading base model: {base_model_name}")
|
| 11 |
-
|
| 12 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 13 |
-
base_model_name,
|
| 14 |
-
torch_dtype=torch.bfloat16,
|
| 15 |
-
device_map="auto",
|
| 16 |
-
load_in_4bit=True, # removes this line only if you upgrade to Pro
|
| 17 |
-
)
|
| 18 |
-
|
| 19 |
-
model = PeftModel.from_pretrained(model, PEFT_MODEL_ID)
|
| 20 |
-
model = model.merge_and_unload()
|
| 21 |
-
|
| 22 |
-
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
|
| 23 |
-
if tokenizer.pad_token is None:
|
| 24 |
-
tokenizer.pad_token = tokenizer.eos_token
|
| 25 |
-
|
| 26 |
-
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 27 |
-
|
| 28 |
-
def respond(message, history):
|
| 29 |
-
messages = []
|
| 30 |
-
for user, assistant in history:
|
| 31 |
-
messages.append({"role": "user", "content": user})
|
| 32 |
-
if assistant:
|
| 33 |
-
messages.append({"role": "assistant", "content": assistant})
|
| 34 |
-
messages.append({"role": "user", "content": message})
|
| 35 |
-
|
| 36 |
-
output = pipe(messages, max_new_tokens=1024, temperature=0.6, do_sample=True)
|
| 37 |
-
return output[0]["generated_text"][-1]["content"]
|
| 38 |
-
|
| 39 |
-
gr.ChatInterface(
|
| 40 |
-
respond,
|
| 41 |
-
title="Java Explainer – Your Own Fine-Tuned Model",
|
| 42 |
-
description="This is 100% your LoRA model, not ChatGPT, not Mistral, not anything else.",
|
| 43 |
-
examples=[
|
| 44 |
-
"Explain this Java code in simple terms: public class Hello { public static void main(String[] args) { System.out.println(\"Hello World\"); }}",
|
| 45 |
-
"What is the difference between == and .equals() in Java?",
|
| 46 |
-
"Why do we mark methods as static in main?"
|
| 47 |
-
]
|
| 48 |
-
).queue().launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|