Spaces:
Sleeping
Sleeping
Neurolingua
commited on
Commit
•
4746643
1
Parent(s):
865104f
Update other_function.py
Browse files- 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"
|
76 |
|
77 |
-
# Save the media content to a file
|
78 |
-
|
79 |
-
with open(
|
80 |
file.write(response.content)
|
81 |
|
82 |
-
print(f"Media downloaded successfully and saved as {
|
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 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
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()
|