Neurolingua commited on
Commit
4746643
1 Parent(s): 865104f

Update other_function.py

Browse files
Files changed (1) hide show
  1. other_function.py +11 -18
other_function.py CHANGED
@@ -63,6 +63,7 @@ def predict_disease(filepath):
63
  result = CLIENT.infer(filepath, model_id="plant-disease-detection-iefbi/1")
64
  return result['predicted_classes'][0]
65
 
 
66
  def convert_img(url, account_sid, auth_token):
67
  try:
68
  # Make the request to the media URL with authentication
@@ -72,28 +73,20 @@ def convert_img(url, account_sid, auth_token):
72
  # Determine a filename from the URL
73
  parsed_url = urlparse(url)
74
  media_id = parsed_url.path.split('/')[-1] # Get the last part of the URL path
75
- filename = f"downloaded_media_{media_id}"
76
 
77
- # Save the media content to a file
78
- media_filepath = os.path.join(UPLOAD_FOLDER, filename)
79
- with open(media_filepath, 'wb') as file:
80
  file.write(response.content)
81
 
82
- print(f"Media downloaded successfully and saved as {media_filepath}")
83
-
84
- # Convert the saved media file to an image
85
- with open(media_filepath, 'rb') as img_file:
86
- image = Image.open(img_file)
87
 
88
- # Optionally, convert the image to JPG and save in UPLOAD_FOLDER
89
- converted_filename = f"image.jpg"
90
- converted_filepath = os.path.join(UPLOAD_FOLDER, converted_filename)
91
- image.convert('RGB').save(converted_filepath, 'JPEG')
92
- return converted_filepath
93
-
94
- except Exception as e:
95
- print(f"Error during image conversion: {e}")
96
- return None
97
 
98
  def get_weather(city):
99
  city=city.strip()
 
63
  result = CLIENT.infer(filepath, model_id="plant-disease-detection-iefbi/1")
64
  return result['predicted_classes'][0]
65
 
66
+
67
  def convert_img(url, account_sid, auth_token):
68
  try:
69
  # Make the request to the media URL with authentication
 
73
  # Determine a filename from the URL
74
  parsed_url = urlparse(url)
75
  media_id = parsed_url.path.split('/')[-1] # Get the last part of the URL path
76
+ filename = f"image.jpg"
77
 
78
+ # Save the media content to a .txt file
79
+ txt_filepath = os.path.join(UPLOAD_FOLDER, filename)
80
+ with open(txt_filepath, 'wb') as file:
81
  file.write(response.content)
82
 
83
+ print(f"Media downloaded successfully and saved as {txt_filepath}")
84
+ return txt_filepath
 
 
 
85
 
86
+ except requests.exceptions.HTTPError as err:
87
+ print(f"HTTP error occurred: {err}")
88
+ except Exception as err:
89
+ print(f"An error occurred: {err}")
 
 
 
 
 
90
 
91
  def get_weather(city):
92
  city=city.strip()