CoolFace
Apppublic

PRC142004/Weather_Forecast_Farmers

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
test_llm.py47 linesDownload Raw Back to root
1# Quick test for LLM integration
2from transformers import pipeline
3import warnings
4
5warnings.filterwarnings('ignore')
6
7print("Testing LLM integration...")
8print("Loading model...")
9
10try:
11    llm_generator = pipeline(
12        "text-generation",
13        model="distilgpt2",
14        max_length=200,
15        device=-1
16    )
17    print("✅ Model loaded successfully!")
18    
19    # Test generation
20    prompt = """As an agricultural expert for Maharashtra, provide specific farming recommendations:
21
22Weather: 6 warning days with overcast conditions
23Severity: WARNING conditions on Saturday, Tuesday, Wednesday, Thursday, Friday, Sunday. 
24
25Recommendations for farmers:
261. Crop protection:"""
27    
28    print("\nGenerating test recommendation...")
29    response = llm_generator(
30        prompt,
31        max_new_tokens=100,
32        num_return_sequences=1,
33        temperature=0.7,
34        do_sample=True,
35        pad_token_id=50256
36    )
37    
38    generated_text = response[0]['generated_text']
39    recommendations = generated_text[len(prompt):].strip()
40    
41    print("\n✅ Generated Recommendation:")
42    print(recommendations)
43    print("\n✅ LLM integration test successful!")
44    
45except Exception as e:
46    print(f"❌ Error: {e}")
47