Update app.py
Browse files
app.py
CHANGED
|
@@ -54,12 +54,13 @@ def search_full_plant_information(plant_name:str):
|
|
| 54 |
search_results = DDGS().text(keywords=query, max_results=5)
|
| 55 |
except DuckDuckGoSearchException as e:
|
| 56 |
if "Ratelimit" in str(e):
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
| 63 |
if search_results:
|
| 64 |
content=""
|
| 65 |
for result in search_results:
|
|
@@ -71,6 +72,11 @@ def search_full_plant_information(plant_name:str):
|
|
| 71 |
response = requests.get(f"{specialtoken}/{prompt}")
|
| 72 |
#print (response.text)
|
| 73 |
return response.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
return f"No data Found for {plant_name}!"
|
| 75 |
|
| 76 |
DB_NAME="plants.db"
|
|
|
|
| 54 |
search_results = DDGS().text(keywords=query, max_results=5)
|
| 55 |
except DuckDuckGoSearchException as e:
|
| 56 |
if "Ratelimit" in str(e):
|
| 57 |
+
try:
|
| 58 |
+
wait_time = 2 ** attempt # Exponential backoff
|
| 59 |
+
print(f"Rate limit hit, retrying in {wait_time} seconds...")
|
| 60 |
+
time.sleep(wait_time)
|
| 61 |
+
except Exception as e:
|
| 62 |
+
pass
|
| 63 |
+
|
| 64 |
if search_results:
|
| 65 |
content=""
|
| 66 |
for result in search_results:
|
|
|
|
| 72 |
response = requests.get(f"{specialtoken}/{prompt}")
|
| 73 |
#print (response.text)
|
| 74 |
return response.text
|
| 75 |
+
else:
|
| 76 |
+
content="Get any information from any source about:"+plant_name
|
| 77 |
+
prompt = PROMPT_TEMPLATE.format(plant_name=plant_name, content=content)
|
| 78 |
+
response = requests.get(f"{specialtoken}/{prompt}")
|
| 79 |
+
return response.text
|
| 80 |
return f"No data Found for {plant_name}!"
|
| 81 |
|
| 82 |
DB_NAME="plants.db"
|