Spaces:
Sleeping
Sleeping
Delete model.py
Browse files
model.py
DELETED
@@ -1,79 +0,0 @@
|
|
1 |
-
import requests
|
2 |
-
import re
|
3 |
-
from typing import List, Dict
|
4 |
-
import os
|
5 |
-
from duckduckgo_search import DDGS
|
6 |
-
|
7 |
-
def search_articles(name: str) -> str:
|
8 |
-
"""Search for 3 newspaper articles containing the name and keywords using DuckDuckGo"""
|
9 |
-
keywords = ['founders', 'partners', 'funders', 'owners']
|
10 |
-
search_query = f'"{name}" ({" OR ".join(keywords)}) site:news'
|
11 |
-
try:
|
12 |
-
with DDGS() as ddgs:
|
13 |
-
results = list(ddgs.text(search_query, max_results=3))
|
14 |
-
if not results:
|
15 |
-
return f"No articles found for {name}"
|
16 |
-
articles = []
|
17 |
-
for i, result in enumerate(results, 1):
|
18 |
-
article = f"**{i}. {result['title']}**\n"
|
19 |
-
article += f"Source: {result['href']}\n"
|
20 |
-
article += f"{result['body']}\n"
|
21 |
-
articles.append(article)
|
22 |
-
return "\n\n".join(articles)
|
23 |
-
except Exception as e:
|
24 |
-
return f"Search failed: {str(e)}"
|
25 |
-
|
26 |
-
def extract_entities(search_results: str) -> str:
|
27 |
-
"""Extract entities using Mistral 7B endpoint"""
|
28 |
-
modal_endpoint = "https://msoaresdiego--mistral-llm-endpoint-fastapi-app.modal.run/generate"
|
29 |
-
|
30 |
-
prompt = f"""Extract all person names and organization names from the following text.
|
31 |
-
Format as:
|
32 |
-
PERSON: [name]
|
33 |
-
ORG: [organization name]
|
34 |
-
|
35 |
-
Text: {search_results}"""
|
36 |
-
|
37 |
-
try:
|
38 |
-
response = requests.post(
|
39 |
-
modal_endpoint,
|
40 |
-
json={
|
41 |
-
"prompt": prompt,
|
42 |
-
"max_tokens": 500,
|
43 |
-
"temperature": 0.1
|
44 |
-
}
|
45 |
-
)
|
46 |
-
if response.status_code == 200:
|
47 |
-
return response.json().get("response", "No entities extracted")
|
48 |
-
else:
|
49 |
-
return f"API Error: {response.status_code}"
|
50 |
-
except Exception as e:
|
51 |
-
return f"Extraction failed: {str(e)}"
|
52 |
-
|
53 |
-
def find_full_names(search_results: str, entities: str) -> str:
|
54 |
-
"""Find full names using Mistral 7B endpoint"""
|
55 |
-
modal_endpoint = "https://msoaresdiego--mistral-llm-endpoint-fastapi-app.modal.run/generate"
|
56 |
-
|
57 |
-
prompt = f"""Based on the search results, find the full names and titles/roles for these entities:
|
58 |
-
|
59 |
-
Entities: {entities}
|
60 |
-
|
61 |
-
Search Results: {search_results}
|
62 |
-
|
63 |
-
Provide full names with their roles/titles where mentioned."""
|
64 |
-
|
65 |
-
try:
|
66 |
-
response = requests.post(
|
67 |
-
modal_endpoint,
|
68 |
-
json={
|
69 |
-
"prompt": prompt,
|
70 |
-
"max_tokens": 300,
|
71 |
-
"temperature": 0.1
|
72 |
-
}
|
73 |
-
)
|
74 |
-
if response.status_code == 200:
|
75 |
-
return response.json().get("response", "No full names found")
|
76 |
-
else:
|
77 |
-
return f"API Error: {response.status_code}"
|
78 |
-
except Exception as e:
|
79 |
-
return f"Full name extraction failed: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|