AkashMnd commited on
Commit
e44aa06
1 Parent(s): b6882d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -8,6 +8,7 @@ import os
8
  genai.configure(api_key=os.getenv("genai"))
9
  oapi_key= os.getenv("openai")
10
 
 
11
  def encode_image(image_file):
12
  with open(image_file.name, "rb") as img_file:
13
  return base64.b64encode(img_file.read()).decode('utf-8')
@@ -123,11 +124,8 @@ def send_to_openai(image_file):
123
  "threshold": "BLOCK_MEDIUM_AND_ABOVE"
124
  },
125
  ]
126
-
127
- model = genai.GenerativeModel(model_name="gemini-1.0-pro",
128
- generation_config=generation_config,
129
- safety_settings=safety_settings)
130
-
131
  prompt_parts = [
132
  "You are a Rice Paddy Agricultural Scientist , You will be given the state of the paddy(a picture description ) and you will have to advice on the correct remedyInput - Sheath Yes Meaning - The Farmer has shown you a picture of Sheath part of the paddy and it is suffering from Sheath Rot , advice the farmer on how to fix thisInput - Sheath No Meaning - The Farmer has shown you a picture of Sheath part of the paddy and it is healthy ,congratulate and advice farmer on how to maintain itInput - Leaf Yes No No Meaning - The Farmer has shown you a picture of Leaf part of the paddy and it is healthy , congratulate the farmer and advice the farmer on how to maintain it Input - Leaf No Yes No Meaning - The Farmer has shown you a picture of Leaf part of the paddy and it has brown spots disease , advice the farmer on how to remedy it Input - Leaf No Yes YesMeaning - The Farmer has shown you a picture of Leaf part of the paddy and it has brown spots disease and Blight Disease , advice the farmer on how to remedy it Input - Leaf No No YesMeaning - The Farmer has shown you a picture of Leaf part of the paddy and it has Blight disease , advice the farmer on how to remedy it Input - Leaf Yes No Yes Meaning - The Farmer has shown you a picture of Leaf part of the paddy and it looks healthy but it has yellowish edges that might indicate blight , advice the farmer on how to remedy it Input - Leaf Yes Yes No Meaning - The Farmer has shown you a picture of Leaf part of the paddy and it has brown spots disease but also is quite green so it might be healthy and just got the brown spot disease , advice the farmer on how to remedy it",
133
  "input: Sheath Yes",
@@ -161,12 +159,19 @@ def send_to_openai(image_file):
161
  new_prompt_parts.append(f"output: {output_key}")
162
  gemini = genai.GenerativeModel(model_name=model)
163
 
164
- response = gemini.generate_content(
165
- contents,
166
- generation_config=generation_config,
167
- safety_settings=safety_settings,
168
- stream=False)
169
- return(response.text)
 
 
 
 
 
 
 
170
 
171
 
172
 
 
8
  genai.configure(api_key=os.getenv("genai"))
9
  oapi_key= os.getenv("openai")
10
 
11
+
12
  def encode_image(image_file):
13
  with open(image_file.name, "rb") as img_file:
14
  return base64.b64encode(img_file.read()).decode('utf-8')
 
124
  "threshold": "BLOCK_MEDIUM_AND_ABOVE"
125
  },
126
  ]
127
+ model = "gemini-1.0-pro"
128
+
 
 
 
129
  prompt_parts = [
130
  "You are a Rice Paddy Agricultural Scientist , You will be given the state of the paddy(a picture description ) and you will have to advice on the correct remedyInput - Sheath Yes Meaning - The Farmer has shown you a picture of Sheath part of the paddy and it is suffering from Sheath Rot , advice the farmer on how to fix thisInput - Sheath No Meaning - The Farmer has shown you a picture of Sheath part of the paddy and it is healthy ,congratulate and advice farmer on how to maintain itInput - Leaf Yes No No Meaning - The Farmer has shown you a picture of Leaf part of the paddy and it is healthy , congratulate the farmer and advice the farmer on how to maintain it Input - Leaf No Yes No Meaning - The Farmer has shown you a picture of Leaf part of the paddy and it has brown spots disease , advice the farmer on how to remedy it Input - Leaf No Yes YesMeaning - The Farmer has shown you a picture of Leaf part of the paddy and it has brown spots disease and Blight Disease , advice the farmer on how to remedy it Input - Leaf No No YesMeaning - The Farmer has shown you a picture of Leaf part of the paddy and it has Blight disease , advice the farmer on how to remedy it Input - Leaf Yes No Yes Meaning - The Farmer has shown you a picture of Leaf part of the paddy and it looks healthy but it has yellowish edges that might indicate blight , advice the farmer on how to remedy it Input - Leaf Yes Yes No Meaning - The Farmer has shown you a picture of Leaf part of the paddy and it has brown spots disease but also is quite green so it might be healthy and just got the brown spot disease , advice the farmer on how to remedy it",
131
  "input: Sheath Yes",
 
159
  new_prompt_parts.append(f"output: {output_key}")
160
  gemini = genai.GenerativeModel(model_name=model)
161
 
162
+ model = genai.GenerativeModel(model_name="gemini-1.0-pro",
163
+ generation_config=generation_config,
164
+ safety_settings=safety_settings)
165
+ response = model.generate_content(prompt_parts)
166
+ input_text=response.text
167
+ output_index = input_text.find("output:")
168
+
169
+ if output_index != -1:
170
+ # Extract the text after "output:"
171
+ output_text = input_text[output_index + len("output:"):].strip()
172
+
173
+ # Print the extracted text
174
+ return output_text
175
 
176
 
177