XMMR12 commited on
Commit
8a5710d
·
verified ·
1 Parent(s): 5c75995

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
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
- 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:
@@ -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"