Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -127,7 +127,14 @@ def search_articles(name: str, max_articles: int = 2) -> str:
|
|
| 127 |
|
| 128 |
|
| 129 |
def extract_entities(search_results: str) -> str:
|
|
|
|
| 130 |
modal_endpoint = "https://msoaresdiego--mistral-llm-endpoint-fastapi-app.modal.run/generate"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
prompt = f"""Extract all person names and organization names from the following text. Do not extract products and service names. Only individuals and organizations. Bring the full details of the name in the newspaper article. For example, if only ACME is mentioned as company name, bring only ACME. IF ACME Inc is mentioned as company name, then you have to extract ACME Inc. In addition, define the relationship between the entity and the company that is being searched. For example, is ACME Inc an owner of the company being searched? Then write 'owner'. Is ACME Inc. a funder of the company being searched? Then write 'funder'
|
| 132 |
Format as:
|
| 133 |
PERSON: [name] - [relationship]
|
|
@@ -137,8 +144,8 @@ Text: {search_results}"""
|
|
| 137 |
try:
|
| 138 |
response = requests.post(
|
| 139 |
modal_endpoint,
|
| 140 |
-
json={"prompt": prompt, "max_tokens":
|
| 141 |
-
timeout=
|
| 142 |
)
|
| 143 |
if response.status_code == 200:
|
| 144 |
return response.json().get("response", "No entities extracted")
|
|
@@ -149,6 +156,7 @@ Text: {search_results}"""
|
|
| 149 |
except Exception as e:
|
| 150 |
return f"[ERROR] Extraction failed: {str(e)}"
|
| 151 |
|
|
|
|
| 152 |
# === Gradio interface functions ===
|
| 153 |
|
| 154 |
def search_only(name: str, article_count: int):
|
|
|
|
| 127 |
|
| 128 |
|
| 129 |
def extract_entities(search_results: str) -> str:
|
| 130 |
+
"""Extract entities using Mistral 7B endpoint"""
|
| 131 |
modal_endpoint = "https://msoaresdiego--mistral-llm-endpoint-fastapi-app.modal.run/generate"
|
| 132 |
+
|
| 133 |
+
# Truncate input to avoid excessive model load
|
| 134 |
+
MAX_CHARS = 8000
|
| 135 |
+
if len(search_results) > MAX_CHARS:
|
| 136 |
+
search_results = search_results[:MAX_CHARS]
|
| 137 |
+
|
| 138 |
prompt = f"""Extract all person names and organization names from the following text. Do not extract products and service names. Only individuals and organizations. Bring the full details of the name in the newspaper article. For example, if only ACME is mentioned as company name, bring only ACME. IF ACME Inc is mentioned as company name, then you have to extract ACME Inc. In addition, define the relationship between the entity and the company that is being searched. For example, is ACME Inc an owner of the company being searched? Then write 'owner'. Is ACME Inc. a funder of the company being searched? Then write 'funder'
|
| 139 |
Format as:
|
| 140 |
PERSON: [name] - [relationship]
|
|
|
|
| 144 |
try:
|
| 145 |
response = requests.post(
|
| 146 |
modal_endpoint,
|
| 147 |
+
json={"prompt": prompt, "max_tokens": 1000, "temperature": 0.15},
|
| 148 |
+
timeout=90 # Increased timeout
|
| 149 |
)
|
| 150 |
if response.status_code == 200:
|
| 151 |
return response.json().get("response", "No entities extracted")
|
|
|
|
| 156 |
except Exception as e:
|
| 157 |
return f"[ERROR] Extraction failed: {str(e)}"
|
| 158 |
|
| 159 |
+
|
| 160 |
# === Gradio interface functions ===
|
| 161 |
|
| 162 |
def search_only(name: str, article_count: int):
|