2001muhammadumair commited on
Commit
2fd9e56
·
verified ·
1 Parent(s): 11cf524

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -14
app.py CHANGED
@@ -3,19 +3,12 @@ from PIL import Image
3
  import torch
4
  from transformers import AutoModelForImageClassification, AutoFeatureExtractor
5
  from groq import Groq
6
- from dotenv import load_dotenv
7
- import os
8
 
9
- # Load environment variables from the .env file
10
- load_dotenv()
11
-
12
- # Securely get the GROQ API key from environment variables
13
- groq_api_key = os.getenv("GROQ_API_KEY")
14
- if not groq_api_key:
15
  raise ValueError("GROQ_API_KEY environment variable not set.")
16
-
17
- # Initialize the client with the API key
18
- client = Groq(api_key=groq_api_key)
19
 
20
  # Expanded dictionary with treatments for various diseases
21
  disease_treatments = {
@@ -93,7 +86,7 @@ if uploaded_file is not None:
93
  top_indices = top_indices[0].tolist()
94
 
95
  # Define a confidence threshold
96
- confidence_threshold = 0.7
97
  class_labels = model.config.id2label
98
  predicted_disease = "Unknown Disease"
99
  predicted_confidence = top_probs[0]
@@ -149,7 +142,6 @@ if uploaded_file is not None:
149
  "content": (
150
  "You are a plant disease analysis assistant. Your task is to provide a comprehensive, actionable diagnosis report."
151
  "The report should include the predicted disease, its symptoms, recommended treatments, and prevention tips. "
152
-
153
  "Ensure the report is actionable and easy to understand for non-experts in agriculture."
154
  )
155
  },
@@ -160,7 +152,7 @@ if uploaded_file is not None:
160
  ],
161
  model="mixtral-8x7b-32768", # Adjust this to the model you're using
162
  temperature=0.7, # Adjust to balance creativity and precision
163
- max_tokens=5000 # Limit to ensure the output is not cut off
164
  )
165
 
166
  # Display the generated report in the Streamlit app
 
3
  import torch
4
  from transformers import AutoModelForImageClassification, AutoFeatureExtractor
5
  from groq import Groq
 
 
6
 
7
+ # Securely load GROQ API key
8
+ grog_api_key = "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"
9
+ if not grog_api_key:
 
 
 
10
  raise ValueError("GROQ_API_KEY environment variable not set.")
11
+ client = Groq(api_key=grog_api_key)
 
 
12
 
13
  # Expanded dictionary with treatments for various diseases
14
  disease_treatments = {
 
86
  top_indices = top_indices[0].tolist()
87
 
88
  # Define a confidence threshold
89
+ confidence_threshold = 0.5
90
  class_labels = model.config.id2label
91
  predicted_disease = "Unknown Disease"
92
  predicted_confidence = top_probs[0]
 
142
  "content": (
143
  "You are a plant disease analysis assistant. Your task is to provide a comprehensive, actionable diagnosis report."
144
  "The report should include the predicted disease, its symptoms, recommended treatments, and prevention tips. "
 
145
  "Ensure the report is actionable and easy to understand for non-experts in agriculture."
146
  )
147
  },
 
152
  ],
153
  model="mixtral-8x7b-32768", # Adjust this to the model you're using
154
  temperature=0.7, # Adjust to balance creativity and precision
155
+ max_tokens=1500 # Limit to ensure the output is not cut off
156
  )
157
 
158
  # Display the generated report in the Streamlit app