visproj commited on
Commit
6c1dedd
·
verified ·
1 Parent(s): fd8c72f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -47
app.py CHANGED
@@ -154,55 +154,37 @@ def healthcare_software_trend_analyzer(product_keyword: str, timeframe: str = 't
154
  "Medical Billing Software", "Practice Management Software",
155
  "Remote Patient Monitoring", "Healthcare CRM", "Medical Imaging Software","Sig", "Patient Instructions"
156
  ]
157
- max_retries = 3
158
- base_delay = 60 # 60 seconds base delay
159
-
160
- for attempt in range(max_retries):
161
- try:
162
- pytrends = TrendReq(hl='en-US', tz=360, timeout=(10,25), retries=2, backoff_factor=0.1)
163
- pytrends.build_payload([product_keyword], timeframe=timeframe, geo=geo)
164
- interest_over_time = pytrends.interest_over_time()
165
-
166
- # Suggest category if not in list
167
- if product_keyword not in HEALTHCARE_SOFTWARE_CATEGORIES:
168
- suggestion = f"\nNote: '{product_keyword}' is not in our list of common healthcare software categories. Consider using one of these: {', '.join(HEALTHCARE_SOFTWARE_CATEGORIES)}\n"
169
- else:
170
- suggestion = ""
171
-
172
- # Google Trends analysis
173
- pytrends = TrendReq(hl='en-US', tz=360)
174
- pytrends.build_payload([product_keyword], timeframe=timeframe, geo=geo)
175
- interest_over_time = pytrends.interest_over_time()
176
-
177
- # Calculate trend metrics
178
- current_interest = interest_over_time[product_keyword].iloc[-1]
179
- avg_interest = interest_over_time[product_keyword].mean()
180
- trend_direction = "Increasing" if current_interest > avg_interest else "Decreasing"
181
-
182
- # Compile report
183
- report = f"Healthcare Software Market Trend Analysis for '{product_keyword}':\n"
184
- report += f"Timeframe: {timeframe}\n"
185
- report += f"Region: {geo if geo else 'Worldwide'}\n\n"
186
- report += f"Google Trends Analysis:\n"
187
- report += f"- Current Interest: {current_interest:.2f}\n"
188
- report += f"- Average Interest: {avg_interest:.2f}\n"
189
- report += f"- Trend Direction: {trend_direction}\n"
190
- report += suggestion
191
 
192
-
193
- return report
 
 
 
 
 
 
 
194
 
195
- except Exception as e:
196
- if "quota" in str(e).lower() or "429" in str(e):
197
- if attempt < max_retries - 1:
198
- delay = base_delay * (2 ** attempt) + random.uniform(0, 10)
199
- time.sleep(delay)
200
- else:
201
- return f"❌ Rate limit exceeded. Please try again later."
202
- else:
203
- return f"❌ Error analyzing healthcare software market trends: {str(e)}"
204
-
205
- return "❌ Failed to retrieve data after multiple attempts."
206
 
207
  @tool
208
  def get_current_time_in_timezone(timezone: str) -> str:
 
154
  "Medical Billing Software", "Practice Management Software",
155
  "Remote Patient Monitoring", "Healthcare CRM", "Medical Imaging Software","Sig", "Patient Instructions"
156
  ]
157
+ try:
158
+ # Suggest category if not in list
159
+ if product_keyword not in HEALTHCARE_SOFTWARE_CATEGORIES:
160
+ suggestion = f"\nNote: '{product_keyword}' is not in our list of common healthcare software categories. Consider using one of these: {', '.join(HEALTHCARE_SOFTWARE_CATEGORIES)}\n"
161
+ else:
162
+ suggestion = ""
163
+
164
+ # Google Trends analysis
165
+ pytrends = TrendReq(hl='en-US', tz=360)
166
+ pytrends.build_payload([product_keyword], timeframe=timeframe, geo=geo)
167
+ interest_over_time = pytrends.interest_over_time()
168
+
169
+ # Calculate trend metrics
170
+ current_interest = interest_over_time[product_keyword].iloc[-1]
171
+ avg_interest = interest_over_time[product_keyword].mean()
172
+ trend_direction = "Increasing" if current_interest > avg_interest else "Decreasing"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
+ # Compile report
175
+ report = f"Healthcare Software Market Trend Analysis for '{product_keyword}':\n"
176
+ report += f"Timeframe: {timeframe}\n"
177
+ report += f"Region: {geo if geo else 'Worldwide'}\n\n"
178
+ report += f"Google Trends Analysis:\n"
179
+ report += f"- Current Interest: {current_interest:.2f}\n"
180
+ report += f"- Average Interest: {avg_interest:.2f}\n"
181
+ report += f"- Trend Direction: {trend_direction}\n"
182
+ report += suggestion
183
 
184
+ return report
185
+
186
+ except Exception as e:
187
+ return f"❌ Error analyzing healthcare software market trends: {str(e)}"
 
 
 
 
 
 
 
188
 
189
  @tool
190
  def get_current_time_in_timezone(timezone: str) -> str: