Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
4 |
+
from peft import PeftModel
|
5 |
+
import torch
|
6 |
+
|
7 |
+
# Load base model and LoRA adapter
|
8 |
+
base_model_id = "openlm-research/open_llama_3b"
|
9 |
+
adapter_path = "jalonso24/lora-lateblight-v3"
|
10 |
+
|
11 |
+
base_model = AutoModelForCausalLM.from_pretrained(base_model_id, torch_dtype=torch.float32)
|
12 |
+
model = PeftModel.from_pretrained(base_model, adapter_path)
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
|
14 |
+
|
15 |
+
model.eval()
|
16 |
+
|
17 |
+
# Inference function
|
18 |
+
def predict_risk(prompt):
|
19 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
20 |
+
with torch.no_grad():
|
21 |
+
outputs = model.generate(
|
22 |
+
**inputs,
|
23 |
+
max_new_tokens=20,
|
24 |
+
temperature=0.7,
|
25 |
+
do_sample=True,
|
26 |
+
pad_token_id=tokenizer.eos_token_id
|
27 |
+
)
|
28 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
29 |
+
return response
|
30 |
+
|
31 |
+
# Gradio UI
|
32 |
+
examples = [
|
33 |
+
[
|
34 |
+
"La variedad es INIA-302 Amarilis, sembrada en noviembre.\nLa precipitaci贸n fue 18.4 mm, la temperatura m谩xima 17.2掳C, la m铆nima 6.1掳C y la humedad promedio 84.12%.\n\n驴Cu谩l es el riesgo de tiz贸n tard铆o?"
|
35 |
+
]
|
36 |
+
]
|
37 |
+
|
38 |
+
description = """
|
39 |
+
### 馃И Predict Late Blight Risk using `lora-lateblight-v3`
|
40 |
+
Enter a weather and crop scenario in Spanish, and the model will respond with the predicted level of late blight risk.
|
41 |
+
"""
|
42 |
+
|
43 |
+
gr.Interface(
|
44 |
+
fn=predict_risk,
|
45 |
+
inputs=gr.Textbox(lines=6, label="Input Prompt (in Spanish)"),
|
46 |
+
outputs=gr.Textbox(lines=4, label="Model Prediction"),
|
47 |
+
title="馃尡 Late Blight Risk Predictor",
|
48 |
+
description=description,
|
49 |
+
examples=examples
|
50 |
+
).launch()
|