Spaces:
Sleeping
Sleeping
fix bugs
Browse files
app.py
CHANGED
|
@@ -47,20 +47,22 @@ def url_to_news(url:str)-> dict:
|
|
| 47 |
response = requests.get(url, timeout=10, headers=headers)
|
| 48 |
response.raise_for_status()
|
| 49 |
|
| 50 |
-
# Check content type to avoid processing non-HTML content
|
| 51 |
content_type = response.headers.get('content-type', '')
|
| 52 |
if 'text/html' not in content_type:
|
| 53 |
-
return {"title": "
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
def support_decision(model, claim:str, news:dict=None)-> str:
|
| 66 |
"""A tool that decides if a given news article supports, contradicts or have an unclear opinion about a given claim
|
|
@@ -70,6 +72,8 @@ def support_decision(model, claim:str, news:dict=None)-> str:
|
|
| 70 |
"""
|
| 71 |
if news is None:
|
| 72 |
news = {"title": "", "context": ""}
|
|
|
|
|
|
|
| 73 |
|
| 74 |
prompt = f"""
|
| 75 |
Analyse the sentiment of the provided news article in contrast with the given claim and respond with only one of the following words
|
|
@@ -90,7 +94,7 @@ def support_decision(model, claim:str, news:dict=None)-> str:
|
|
| 90 |
if response in ["supports", "contradicts", "unclear"]:
|
| 91 |
return response
|
| 92 |
else:
|
| 93 |
-
return "unclear"
|
| 94 |
except Exception:
|
| 95 |
return "unclear"
|
| 96 |
|
|
|
|
| 47 |
response = requests.get(url, timeout=10, headers=headers)
|
| 48 |
response.raise_for_status()
|
| 49 |
|
|
|
|
| 50 |
content_type = response.headers.get('content-type', '')
|
| 51 |
if 'text/html' not in content_type:
|
| 52 |
+
return {"title": "Error", "context": "Non-HTML content"}
|
| 53 |
|
| 54 |
+
soup = BeautifulSoup(response.content, "html.parser")
|
| 55 |
+
if soup.title:
|
| 56 |
+
title = soup.title.text
|
| 57 |
+
else:
|
| 58 |
+
title = ""
|
| 59 |
+
|
| 60 |
+
context = soup.get_text()[:5000]
|
| 61 |
|
| 62 |
+
return {"title": title, "context": context}
|
| 63 |
+
|
| 64 |
+
except Exception as e:
|
| 65 |
+
return {"title": "Error", "context": f"Failed to process URL: {str(e)}"}
|
| 66 |
|
| 67 |
def support_decision(model, claim:str, news:dict=None)-> str:
|
| 68 |
"""A tool that decides if a given news article supports, contradicts or have an unclear opinion about a given claim
|
|
|
|
| 72 |
"""
|
| 73 |
if news is None:
|
| 74 |
news = {"title": "", "context": ""}
|
| 75 |
+
if news["title"] == "Error":
|
| 76 |
+
return "unclear"
|
| 77 |
|
| 78 |
prompt = f"""
|
| 79 |
Analyse the sentiment of the provided news article in contrast with the given claim and respond with only one of the following words
|
|
|
|
| 94 |
if response in ["supports", "contradicts", "unclear"]:
|
| 95 |
return response
|
| 96 |
else:
|
| 97 |
+
return "unclear"
|
| 98 |
except Exception:
|
| 99 |
return "unclear"
|
| 100 |
|