File size: 3,094 Bytes
1e97531
 
 
 
 
 
 
 
 
 
 
 
 
 
eee60b8
6603260
1e97531
4c45c64
 
 
 
 
 
 
 
 
 
 
 
 
 
aaee255
1e97531
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d0f066e
4c45c64
 
a4f3208
 
1e97531
 
 
 
 
 
 
 
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
from flask import Flask, request, jsonify ,render_template , redirect
from pydantic import BaseModel
import pickle
import json
import pandas as pd
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.inception_v3 import preprocess_input
import numpy as np
import os
import gdown
import lightgbm as lgb
from PIL import Image
from flask_cors import CORS, cross_origin

# import wikipedia as wiki

from huggingface_hub import hf_hub_download
from pyllamacpp.model import Model

#Download the model
hf_hub_download(repo_id="LLukas22/gpt4all-lora-quantized-ggjt", filename="ggjt-model.bin", local_dir=".")

#Load the model
model = Model(ggml_model="ggjt-model.bin", n_ctx=2000)

#Generate
# prompt="User: How are you doing?\nBot:"

# result=model.generate(prompt,n_predict=50)


app = Flask(__name__)

id = "1dPrnyH7y9ojSHaOOOTkbGkCnhwYvMxab"
output = "disease_new.h5"
gdown.download(id=id, output=output, quiet=False)
   
CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'

crop_disease_ml=load_model('disease_new.h5')

@app.route("/upload-image", methods=["POST"])
@cross_origin()
def upload_image():
    # if request.method == "POST":
        if request.files:
            imag = request.files["image"]
            try:
                contents = imag.read()
                with open(imag.filename, 'wb') as f:
                    f.write(contents)
            except Exception:
                return {"message": "There was an error uploading the file"}
            finally:
                imag.close()
            print(imag)
            classes = ['Pepper bell  Bacterial spot', 'Pepper bell  healthy', 'Potato  Early blight', 'Potato  Late blight', 'Potato  healthy', 'Tomato Bacterial spot', 'Tomato Early blight', 'Tomato Late blight', 'Tomato Leaf Mold', 'Tomato Septoria leaf spot', 'Tomato Spider mites Two spotted spider mite', 'Tomato Target Spot', 'Tomato Tomato YellowLeaf Curl Virus', 'Tomato Tomato mosaic virus', 'Tomato healthy']
            img=image.load_img(str(imag.filename),target_size=(224,224))
            x=image.img_to_array(img)
            x=x/255
            img_data=np.expand_dims(x,axis=0)
            prediction = crop_disease_ml.predict(img_data)
            predictions = list(prediction[0])
            max_num = max(predictions)
            index = predictions.index(max_num)
            print(classes[index])
            os.remove(str(imag.filename))
            result=model.generate("Information and Precaution Instructions about " +str(classes[index]) +"is",n_predict=50)

            # result = wiki.summary(str(classes[index]))
            response = jsonify(output=classes[index],desc = result)

            # response.headers.add('Access-Control-Allow-Origin', '*')
            # response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
            # response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
            return response


if __name__ =="__main__":
    app.run(debug=False,host="0.0.0.0",port=5000)