Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import PeftModel, PeftConfig, AutoModelForCausalLM
|
3 |
+
|
4 |
+
# Load the PEFT model
|
5 |
+
config = PeftConfig.from_pretrained("Maouu/billythecook")
|
6 |
+
base_model = AutoModelForCausalLM.from_pretrained("unsloth/llama-3-8b-bnb-4bit")
|
7 |
+
model = PeftModel.from_pretrained("unsloth/llama-3-8b-bnb-4bit", config=config)
|
8 |
+
|
9 |
+
def generate_text(prompt):
|
10 |
+
# Generate text using the model
|
11 |
+
output = model.generate(prompt, max_length=50, num_return_sequences=1, return_tensors="pt")
|
12 |
+
generated_text = model.tokenizer.decode(output[0], skip_special_tokens=True)
|
13 |
+
return generated_text
|
14 |
+
|
15 |
+
iface = gr.Interface(fn=generate_text, inputs="text", outputs="text", title="PEFT Text Generation")
|
16 |
+
iface.launch()
|