Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Hugging Face's logo
|
| 2 |
+
Hugging Face
|
| 3 |
+
Models
|
| 4 |
+
Datasets
|
| 5 |
+
Spaces
|
| 6 |
+
Community
|
| 7 |
+
Docs
|
| 8 |
+
Pricing
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
Hugging Face is way more fun with friends and colleagues! 🤗 Join an organization
|
| 13 |
+
Spaces:
|
| 14 |
+
|
| 15 |
+
ubiodee
|
| 16 |
+
/
|
| 17 |
+
LearnPlutus
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
like
|
| 21 |
+
0
|
| 22 |
+
|
| 23 |
+
App
|
| 24 |
+
Files
|
| 25 |
+
Community
|
| 26 |
+
Settings
|
| 27 |
+
LearnPlutus
|
| 28 |
+
/
|
| 29 |
+
app.py
|
| 30 |
+
|
| 31 |
+
ubiodee's picture
|
| 32 |
+
ubiodee
|
| 33 |
+
Create app.py
|
| 34 |
+
df07275
|
| 35 |
+
verified
|
| 36 |
+
39 minutes ago
|
| 37 |
+
raw
|
| 38 |
+
|
| 39 |
+
Copy download link
|
| 40 |
+
history
|
| 41 |
+
blame
|
| 42 |
+
edit
|
| 43 |
+
delete
|
| 44 |
+
|
| 45 |
+
1.11 kB
|
| 46 |
+
import gradio as gr
|
| 47 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 48 |
+
from peft import PeftModel
|
| 49 |
+
import torch
|
| 50 |
+
|
| 51 |
+
# Replace with your model repository ID
|
| 52 |
+
model_repo_id = "ubiodee/Plutuslearn-Llama-3.2-3B-Instruct"
|
| 53 |
+
|
| 54 |
+
# Load the tokenizer
|
| 55 |
+
tokenizer = AutoTokenizer.from_pretrained(model_repo_id)
|
| 56 |
+
|
| 57 |
+
# Load the base model and apply the PEFT adapter
|
| 58 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 59 |
+
"meta-llama/Llama-3.2-3B-Instruct",
|
| 60 |
+
torch_dtype=torch.float16,
|
| 61 |
+
device_map="auto"
|
| 62 |
+
)
|
| 63 |
+
model = PeftModel.from_pretrained(base_model, model_repo_id)
|
| 64 |
+
|
| 65 |
+
# Define the prediction function
|
| 66 |
+
def predict(text):
|
| 67 |
+
inputs = tokenizer(text, return_tensors="pt").to("cuda")
|
| 68 |
+
outputs = model.generate(**inputs, max_length=100) # Adjust parameters as needed
|
| 69 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 70 |
+
|
| 71 |
+
# Create Gradio interface
|
| 72 |
+
demo = gr.Interface(
|
| 73 |
+
fn=predict,
|
| 74 |
+
inputs=gr.Textbox(label="Input Text"),
|
| 75 |
+
outputs=gr.Textbox(label="Model Output"),
|
| 76 |
+
title="My Model Demo",
|
| 77 |
+
description="Test the fine-tuned model hosted on Hugging Face."
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
# Launch the app
|
| 81 |
+
demo.launch()
|