Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -49,27 +49,28 @@ def search_full_plant_information(plant_name:str):
|
|
| 49 |
""" """
|
| 50 |
query = f"{plant_name} plant medicinal uses scientific information site:.edu OR site:.gov OR site:.org"
|
| 51 |
search_results=""
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
| 73 |
return f"No data Found for {plant_name}!"
|
| 74 |
|
| 75 |
DB_NAME="plants.db"
|
|
|
|
| 49 |
""" """
|
| 50 |
query = f"{plant_name} plant medicinal uses scientific information site:.edu OR site:.gov OR site:.org"
|
| 51 |
search_results=""
|
| 52 |
+
for attempt in range(3): # Retry up to 3 times
|
| 53 |
+
try:
|
| 54 |
+
search_results = DDGS().text(keywords=query, max_results=5)
|
| 55 |
+
except DuckDuckGoSearchException as e:
|
| 56 |
+
if "Ratelimit" in str(e):
|
| 57 |
+
wait_time = 2 ** attempt # Exponential backoff
|
| 58 |
+
print(f"Rate limit hit, retrying in {wait_time} seconds...")
|
| 59 |
+
time.sleep(wait_time)
|
| 60 |
+
else:
|
| 61 |
+
raise
|
| 62 |
+
raise Exception("Failed to fetch data after retries due to rate limiting.")
|
| 63 |
+
if search_results:
|
| 64 |
+
content=""
|
| 65 |
+
for result in search_results:
|
| 66 |
+
#content+=requests.get(f"{specialtoken}/Analyze this:{result['body']}").text
|
| 67 |
+
content+=result['body']+" "
|
| 68 |
+
content+=fetch_page_content(result['href'])+" "
|
| 69 |
+
time.sleep(2)
|
| 70 |
+
prompt = PROMPT_TEMPLATE.format(plant_name=plant_name, content=content)
|
| 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"
|