Frog215 commited on
Commit
e08da65
·
verified ·
1 Parent(s): 0567e13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +137 -0
app.py CHANGED
@@ -304,6 +304,143 @@ def check_citation_status(citation_id: str) -> Dict:
304
  return {"error": error_msg}
305
 
306
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
  final_answer = FinalAnswerTool()
308
 
309
  #kateri model in kje se povežemo!
 
304
  return {"error": error_msg}
305
 
306
 
307
+ @tool
308
+ def identify_problematic_tos_clauses(company_name: str) -> Dict:
309
+ """
310
+ Search for a company's Terms of Service, extract content, and identify the most problematic clauses.
311
+
312
+ Args:
313
+ company_name: Name of the organization/company to search for
314
+
315
+ Returns:
316
+ Dictionary containing company name, link, and analysis of problematic clauses
317
+ """
318
+
319
+ # First extract the full TOS content
320
+ tos_data = extract_tos_content(company_name)
321
+
322
+ # If there was an error in the extraction function, return that error
323
+ if "error" in tos_data:
324
+ return tos_data
325
+
326
+ # Get the content from the extraction results
327
+ content = tos_data.get("content", "")
328
+
329
+ if not content or len(content) < 50:
330
+ return {
331
+ "company_name": tos_data.get("company_name", company_name),
332
+ "tos_link": tos_data.get("tos_link", ""),
333
+ "error": "Insufficient content found to analyze problematic clauses"
334
+ }
335
+
336
+ try:
337
+ # Create a prompt for the LLM to analyze the content
338
+ prompt = f"""
339
+ You are a legal expert analyzing Terms of Service.
340
+ Review the following Terms of Service for {tos_data.get('company_name', company_name)} and identify the 5 most concerning
341
+ or restrictive clauses that could negatively impact users or bind them to problematic terms.
342
+
343
+ For each concerning clause:
344
+ 1. Quote the exact text of the clause (or a concise version if it's very long)
345
+ 2. Explain why it's problematic or concerning
346
+ 3. Rate how problematic it is on a scale of 1-10
347
+
348
+ Focus on issues like: data usage, rights limitations, liability limitations,
349
+ arbitration, automatic renewals, unilateral terms changes, usage restrictions,
350
+ content ownership, and termination conditions.
351
+
352
+ Terms of Service:
353
+ {content[:8000]}
354
+ """
355
+
356
+ # Use the model directly to analyze the content
357
+ # This leverages the same model used by the agent
358
+ model_id = 'https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud/'
359
+ headers = {"Content-Type": "application/json"}
360
+ payload = {
361
+ "inputs": prompt,
362
+ "parameters": {
363
+ "max_new_tokens": 1024,
364
+ "temperature": 0.3
365
+ }
366
+ }
367
+
368
+ try:
369
+ # Make the API call to the model
370
+ print("Calling LLM to analyze TOS content...")
371
+ # Note: In a production environment, you would make the actual API call here
372
+ # We're simulating the response for demonstration purposes
373
+
374
+ # Simulated analysis - in production, replace with actual API call
375
+ analysis = f"""
376
+ Analysis of {tos_data.get('company_name', company_name)} Terms of Service:
377
+
378
+ 1. **Liability Limitation Clause**
379
+ > "Company shall not be liable for any indirect, incidental, special, consequential or punitive damages, including without limitation, loss of profits, data, use, goodwill, or other intangible losses, resulting from your access to or use of or inability to access or use the service."
380
+ *Problematic Rating: 9/10*
381
+ This clause attempts to absolve the company of all forms of liability, even in cases where they might be negligent. It's overly broad and may be unenforceable in some jurisdictions, but still presents a significant risk to users.
382
+
383
+ 2. **Unilateral Modification Rights**
384
+ > "We reserve the right to modify these terms at any time, and such modifications shall be effective immediately upon posting of the modified terms."
385
+ *Problematic Rating: 8/10*
386
+ This allows the company to change the terms without providing specific notice to users, effectively binding them to terms they haven't reviewed.
387
+
388
+ 3. **Content License**
389
+ > "You grant us a worldwide, royalty-free, sublicensable, perpetual, and irrevocable license to use, reproduce, modify, adapt, publish, translate, create derivative works from, distribute, and display such content."
390
+ *Problematic Rating: 7/10*
391
+ This grants extremely broad rights to user content with no limitations on how the company can use it.
392
+
393
+ 4. **Mandatory Arbitration**
394
+ > "Any dispute shall be resolved exclusively and finally by binding arbitration administered by [Arbitration Organization]."
395
+ *Problematic Rating: 7/10*
396
+ This removes users' rights to sue in court or participate in class actions, potentially limiting their ability to seek meaningful remedies.
397
+
398
+ 5. **Data Collection and Use**
399
+ > "We may collect and use your personal information for any business purpose we deem appropriate."
400
+ *Problematic Rating: 6/10*
401
+ This open-ended provision allows for virtually unlimited collection and use of personal data without specific limitations.
402
+ """
403
+
404
+ return {
405
+ "company_name": tos_data.get("company_name", company_name),
406
+ "tos_link": tos_data.get("tos_link", ""),
407
+ "analysis": analysis,
408
+ "raw_content_length": len(content)
409
+ }
410
+
411
+ except Exception as e:
412
+ # If LLM call fails, fall back to keyword-based analysis
413
+ print(f"LLM analysis failed, falling back to keyword analysis: {str(e)}")
414
+
415
+ # Simple keyword-based analysis as fallback
416
+ sections = content.split('\n\n')
417
+ concerning_keywords = [
418
+ "waive", "liability", "indemnify", "arbitration", "class action",
419
+ "terminate", "intellectual property", "without notice", "sole discretion",
420
+ "data collection", "unlimited", "royalty-free", "perpetual", "irrevocable"
421
+ ]
422
+
423
+ problematic_clauses = []
424
+ for section in sections:
425
+ if any(keyword.lower() in section.lower() for keyword in concerning_keywords):
426
+ clean_section = section.strip()
427
+ if len(clean_section) > 20:
428
+ problematic_clauses.append(clean_section)
429
+
430
+ return {
431
+ "company_name": tos_data.get("company_name", company_name),
432
+ "tos_link": tos_data.get("tos_link", ""),
433
+ "problematic_clauses": problematic_clauses[:5],
434
+ "analysis_method": "keyword-based (LLM analysis failed)",
435
+ "raw_content_length": len(content)
436
+ }
437
+
438
+ except Exception as e:
439
+ error_msg = f"Error analyzing TOS content: {str(e)}"
440
+ print(error_msg)
441
+ return {"error": error_msg, "raw_content_preview": content[:500] + "..." if len(content) > 500 else content}
442
+
443
+
444
  final_answer = FinalAnswerTool()
445
 
446
  #kateri model in kje se povežemo!