jays009 commited on
Commit
ce20917
·
verified ·
1 Parent(s): b4a7338

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -27
app.py CHANGED
@@ -4,7 +4,6 @@ from torch import nn
4
  from torchvision import models, transforms
5
  from huggingface_hub import hf_hub_download
6
  from PIL import Image
7
- from flask import Flask, request, jsonify
8
 
9
  # Define the number of classes
10
  num_classes = 2 # Update with the actual number of classes in your dataset (e.g., 2 for healthy and anomalous)
@@ -62,29 +61,5 @@ iface = gr.Interface(
62
  description="Upload an image of wheat to detect anomalies like disease or pest infestation."
63
  )
64
 
65
- # Launch the Gradio interface on a different port
66
- iface.launch(share=True, server_port=7861)
67
-
68
- # Create a Flask app
69
- app = Flask(__name__)
70
-
71
- # Define the API endpoint
72
- @app.route('/predict', methods=['POST'])
73
- def api_predict():
74
- try:
75
- data = request.json
76
- image_path = data['inputs']
77
-
78
- # Load the image
79
- image = Image.open(image_path)
80
-
81
- # Perform prediction
82
- result = predict(image)
83
-
84
- return jsonify({"result": result})
85
- except Exception as e:
86
- return jsonify({"error": str(e)}), 400
87
-
88
- # Run the Flask app on a different port
89
- if __name__ == '__main__':
90
- app.run(host='0.0.0.0', port=8001)
 
4
  from torchvision import models, transforms
5
  from huggingface_hub import hf_hub_download
6
  from PIL import Image
 
7
 
8
  # Define the number of classes
9
  num_classes = 2 # Update with the actual number of classes in your dataset (e.g., 2 for healthy and anomalous)
 
61
  description="Upload an image of wheat to detect anomalies like disease or pest infestation."
62
  )
63
 
64
+ # Launch the Gradio interface
65
+ iface.launch()