File size: 2,918 Bytes
77d75db
 
 
 
 
 
 
 
f82fbd5
77d75db
 
88cc76c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: Crop Diag Module
emoji: 🐢
colorFrom: gray
colorTo: pink
sdk: docker
pinned: false
short_description: Crop diagnosis module
app_port: 8000
---


# Crop Diagnosis Knowledge Graph Module

A powerful tool for querying crop diagnosis knowledge graphs using LangChain and Neo4j. This module provides an API interface to interact with a knowledge graph containing agricultural and crop disease information.

## Features

- Natural language querying of crop diagnosis knowledge graph
- Integration with LangChain for intelligent query processing
- Neo4j database backend for efficient graph operations
- RESTful API interface
- Environment-based configuration

## Prerequisites

- Python 3.8+
- Neo4j Database (version 5.x)
- OpenAI API key (for LangChain integration)

## Installation

1. Clone the repository:
```bash
git clone [repository-url]
cd crop-diag-module
```

2. Create and activate a virtual environment:
```bash
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
```

3. Install dependencies:
```bash
pip install -r requirements.txt
```

## Configuration

1. Create a `.env` file in the project root:
```bash
cp .env.example .env
```

2. Edit the `.env` file with your configuration:
```env
# Neo4j Configuration
NEO4J_URI=bolt://localhost:7687
NEO4J_USER=neo4j
NEO4J_PASSWORD=your_password

# API Configuration
API_HOST=0.0.0.0
API_PORT=8000
DEBUG=True

# LangChain Configuration
OPENAI_API_KEY=your_openai_api_key
```

Replace the following values:
- `NEO4J_URI`: Your Neo4j database URI
- `NEO4J_USER`: Neo4j username
- `NEO4J_PASSWORD`: Neo4j password
- `OPENAI_API_KEY`: Your OpenAI API key

## Running the Application

1. Start the FastAPI server:
```bash
uvicorn app.main:app --reload
```

2. Access the API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc

## API Usage

### Query the Knowledge Graph

```bash
curl -X POST "http://localhost:8000/api/query" \
     -H "Content-Type: application/json" \
     -d '{"question": "What are the symptoms of rice blast disease?"}'
```

## Project Structure

```
crop-diag-module/
├── app/
│   ├── api/          # API routes and endpoints
│   ├── core/         # Core functionality
│   ├── models/       # Data models
│   └── utils/        # Utility functions
├── KG/               # Knowledge Graph data
├── tests/            # Test cases
├── requirements.txt  # Project dependencies
└── .env             # Environment configuration
```

## Development

### Running Tests

```bash
pytest tests/
```

### Code Style

This project follows PEP 8 style guidelines. Use the following command to check code style:

```bash
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

uvicorn app.main:app --reload
```

## License

[Add your license information here]

## Contributing

[Add contribution guidelines here]