7jimmy commited on
Commit
24537c6
·
verified ·
1 Parent(s): 339b3e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
  import streamlit as st
3
  from PIL import Image
4
  from tensorflow.keras.models import load_model
@@ -10,6 +11,10 @@ UPLOAD_FOLDER = 'static/uploads'
10
  ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'}
11
  TARGET_SIZE = (256, 256)
12
 
 
 
 
 
13
  # Ensure the upload folder exists
14
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
15
 
@@ -42,6 +47,14 @@ def predict_disease(image_path, model):
42
  pred = str(classes[index])
43
  return pred
44
 
 
 
 
 
 
 
 
 
45
  # Streamlit app
46
  st.title("Cotton Disease Detection")
47
  st.write("Upload an image to detect the disease.")
@@ -66,6 +79,11 @@ if uploaded_file is not None:
66
  # Display the uploaded image
67
  st.image(image_path, caption='Uploaded Image.', use_column_width=True)
68
  st.write(f"Prediction: {prediction}")
 
 
 
 
 
69
  else:
70
  st.write("Please upload an image file (png, jpg, jpeg).")
71
  else:
 
1
  import os
2
+ import openai
3
  import streamlit as st
4
  from PIL import Image
5
  from tensorflow.keras.models import load_model
 
11
  ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'}
12
  TARGET_SIZE = (256, 256)
13
 
14
+ # OpenAI API Key (make sure to keep this key secure and not expose it in public repositories)
15
+ OPENAI_API_KEY = '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'
16
+ openai.api_key = OPENAI_API_KEY
17
+
18
  # Ensure the upload folder exists
19
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
20
 
 
47
  pred = str(classes[index])
48
  return pred
49
 
50
+ def get_disease_info(disease_name):
51
+ response = openai.Completion.create(
52
+ engine="text-davinci-003",
53
+ prompt=f"Explain the cause and solution for the following cotton plant disease: {disease_name}",
54
+ max_tokens=150
55
+ )
56
+ return response.choices[0].text.strip()
57
+
58
  # Streamlit app
59
  st.title("Cotton Disease Detection")
60
  st.write("Upload an image to detect the disease.")
 
79
  # Display the uploaded image
80
  st.image(image_path, caption='Uploaded Image.', use_column_width=True)
81
  st.write(f"Prediction: {prediction}")
82
+
83
+ # Get disease information from OpenAI GPT
84
+ disease_info = get_disease_info(prediction)
85
+ st.write("Disease Information:")
86
+ st.write(disease_info)
87
  else:
88
  st.write("Please upload an image file (png, jpg, jpeg).")
89
  else: