update
Browse files
app.py
CHANGED
|
@@ -4,16 +4,17 @@ import torch
|
|
| 4 |
|
| 5 |
model_name = "bharatgenai/AgriParam"
|
| 6 |
|
| 7 |
-
print("Loading AgriParam model... This may take
|
| 8 |
|
| 9 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=
|
| 10 |
|
| 11 |
model = AutoModelForCausalLM.from_pretrained(
|
| 12 |
model_name,
|
| 13 |
-
torch_dtype=torch.float16,
|
| 14 |
-
device_map="cpu",
|
| 15 |
trust_remote_code=True,
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
)
|
| 18 |
|
| 19 |
def chat(message, history):
|
|
@@ -26,7 +27,8 @@ def chat(message, history):
|
|
| 26 |
temperature=0.7,
|
| 27 |
do_sample=True,
|
| 28 |
pad_token_id=tokenizer.eos_token_id,
|
| 29 |
-
eos_token_id=tokenizer.eos_token_id
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
@@ -36,7 +38,7 @@ def chat(message, history):
|
|
| 36 |
demo = gr.ChatInterface(
|
| 37 |
fn=chat,
|
| 38 |
title="🌾 AgriParam - Agriculture Assistant",
|
| 39 |
-
description="Test version
|
| 40 |
examples=[
|
| 41 |
["महाराष्ट्रात कापूस पिकावर लाल किडीचा उपाय काय आहे?"],
|
| 42 |
["Best practices for organic wheat farming in Maharashtra?"],
|
|
|
|
| 4 |
|
| 5 |
model_name = "bharatgenai/AgriParam"
|
| 6 |
|
| 7 |
+
print("Loading AgriParam model... This may take some time on free CPU")
|
| 8 |
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=False)
|
| 10 |
|
| 11 |
model = AutoModelForCausalLM.from_pretrained(
|
| 12 |
model_name,
|
|
|
|
|
|
|
| 13 |
trust_remote_code=True,
|
| 14 |
+
torch_dtype=torch.float16, # Changed to float16 (more compatible on CPU)
|
| 15 |
+
device_map="cpu",
|
| 16 |
+
low_cpu_mem_usage=True,
|
| 17 |
+
attn_implementation="eager" # This helps avoid rope_scaling issues
|
| 18 |
)
|
| 19 |
|
| 20 |
def chat(message, history):
|
|
|
|
| 27 |
temperature=0.7,
|
| 28 |
do_sample=True,
|
| 29 |
pad_token_id=tokenizer.eos_token_id,
|
| 30 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 31 |
+
use_cache=False # Important for stability on CPU
|
| 32 |
)
|
| 33 |
|
| 34 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
| 38 |
demo = gr.ChatInterface(
|
| 39 |
fn=chat,
|
| 40 |
title="🌾 AgriParam - Agriculture Assistant",
|
| 41 |
+
description="Test version on free CPU • English, Hindi & Marathi",
|
| 42 |
examples=[
|
| 43 |
["महाराष्ट्रात कापूस पिकावर लाल किडीचा उपाय काय आहे?"],
|
| 44 |
["Best practices for organic wheat farming in Maharashtra?"],
|