File size: 5,007 Bytes
98d52da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import requests
import json
from typing import List, Dict
from pathlib import Path
import os
from dotenv import load_dotenv

class StrainProcessor:
    def __init__(self):
        """Initialize the Strain Processor with Hugging Face endpoints"""
        load_dotenv()
        
        # Base URL for the Hugging Face space
        self.base_url = "https://huggingface.co/spaces/stephenpalazzo/growing-guide"
        self.headers = {
            "Authorization": f"Bearer {os.getenv('HUGGINGFACE_TOKEN')}",
            "Content-Type": "application/json"
        }

    def process_single_strain(self, strain_data: Dict) -> Dict:
        """
        Process a single strain through the API
        
        Args:
            strain_data (dict): Data for a single strain, e.g.,
            {
                "strain_name": "Blue Dream",
                "difficulty": "Medium",
                "total_time_weeks": 12,
                "optimal_temperature": "20-25°C",
                "optimal_humidity": "40-60%",
                "light_schedule": "18/6 veg, 12/12 flower"
            }
        """
        endpoint = f"{self.base_url}/api/v2/strains/process"
        
        try:
            response = requests.post(
                endpoint,
                headers=self.headers,
                json=strain_data
            )
            response.raise_for_status()
            return response.json()
        except requests.exceptions.RequestException as e:
            print(f"Error processing strain: {e}")
            return {"error": str(e)}

    def process_batch_strains(self, strains: List[Dict]) -> Dict:
        """
        Process multiple strains in batch
        
        Args:
            strains (list): List of strain dictionaries
        """
        endpoint = f"{self.base_url}/api/v2/strains/batch"
        
        try:
            response = requests.post(
                endpoint,
                headers=self.headers,
                json={"strains": strains}
            )
            response.raise_for_status()
            return response.json()
        except requests.exceptions.RequestException as e:
            print(f"Error processing batch: {e}")
            return {"error": str(e)}

    def get_debug_status(self) -> Dict:
        """Check system debug status"""
        endpoint = f"{self.base_url}/debug"
        
        try:
            response = requests.get(
                endpoint,
                headers=self.headers
            )
            response.raise_for_status()
            return response.json()
        except requests.exceptions.RequestException as e:
            print(f"Error getting debug status: {e}")
            return {"error": str(e)}

    def health_check(self) -> Dict:
        """Perform health check"""
        endpoint = f"{self.base_url}/health"
        
        try:
            response = requests.get(
                endpoint,
                headers=self.headers
            )
            response.raise_for_status()
            return response.json()
        except requests.exceptions.RequestException as e:
            print(f"Error performing health check: {e}")
            return {"error": str(e)}

def save_results(data: Dict, filename: str):
    """Helper function to save results to JSON file"""
    results_dir = Path("results")
    results_dir.mkdir(exist_ok=True)
    
    filepath = results_dir / filename
    with open(filepath, 'w') as f:
        json.dump(data, f, indent=2)
    print(f"Results saved to {filepath}")

# Example usage
if __name__ == "__main__":
    processor = StrainProcessor()
    
    # Check system health first
    health_status = processor.health_check()
    print("Health Status:", health_status)
    
    # Process a single strain
    single_strain = {
        "strain_name": "Blue Dream",
        "difficulty": "Medium",
        "total_time_weeks": 12,
        "optimal_temperature": "20-25°C",
        "optimal_humidity": "40-60%",
        "light_schedule": "18/6 veg, 12/12 flower"
    }
    
    result = processor.process_single_strain(single_strain)
    save_results(result, "single_strain_result.json")
    
    # Process multiple strains
    batch_strains = [
        {
            "strain_name": "OG Kush",
            "difficulty": "Hard",
            "total_time_weeks": 10,
            "optimal_temperature": "21-26°C",
            "optimal_humidity": "45-55%",
            "light_schedule": "18/6 veg, 12/12 flower"
        },
        {
            "strain_name": "Northern Lights",
            "difficulty": "Easy",
            "total_time_weeks": 8,
            "optimal_temperature": "20-25°C",
            "optimal_humidity": "40-60%",
            "light_schedule": "18/6 veg, 12/12 flower"
        }
    ]
    
    batch_result = processor.process_batch_strains(batch_strains)
    save_results(batch_result, "batch_strains_result.json")
    
    # Get debug status
    debug_status = processor.get_debug_status()
    save_results(debug_status, "debug_status.json")