Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,6 @@ import torch.nn as nn
|
|
11 |
from transformers import AutoModel
|
12 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
13 |
import gradio as gr
|
14 |
-
import brotli
|
15 |
|
16 |
client = AsyncClient(
|
17 |
# enable http2
|
@@ -26,25 +25,17 @@ client = AsyncClient(
|
|
26 |
)
|
27 |
|
28 |
def parse_comments(response: Response) -> Dict:
|
29 |
-
log.debug(f"Response status code: {response.status_code}")
|
30 |
-
log.debug(f"Response headers: {response.headers}")
|
31 |
-
|
32 |
try:
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
response_text = response.text
|
37 |
-
data = json.loads(response_text)
|
38 |
-
except json.JSONDecodeError as e:
|
39 |
-
log.error(f"Failed to parse JSON response: {e}")
|
40 |
-
log.error(f"Response text: {response_text[:200]}") # Log only the first 200 characters
|
41 |
return {"comments": [], "total_comments": 0}
|
42 |
|
43 |
comments_data = data.get("comments", [])
|
44 |
total_comments = data.get("total", 0)
|
45 |
|
46 |
if not comments_data:
|
47 |
-
log.warning(f"No comments found in response: {
|
48 |
return {"comments": [], "total_comments": total_comments}
|
49 |
|
50 |
parsed_comments = []
|
@@ -61,7 +52,7 @@ def parse_comments(response: Response) -> Dict:
|
|
61 |
async def scrape_comments(post_id: int, comments_count: int = 20, max_comments: int = None) -> List[Dict]:
|
62 |
|
63 |
def form_api_url(cursor: int):
|
64 |
-
base_url = "https://www.tiktok.com/api/comment/list/?"
|
65 |
params = {
|
66 |
"aweme_id": post_id,
|
67 |
'count': comments_count,
|
|
|
11 |
from transformers import AutoModel
|
12 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
13 |
import gradio as gr
|
|
|
14 |
|
15 |
client = AsyncClient(
|
16 |
# enable http2
|
|
|
25 |
)
|
26 |
|
27 |
def parse_comments(response: Response) -> Dict:
|
|
|
|
|
|
|
28 |
try:
|
29 |
+
data = json.loads(response.text)
|
30 |
+
except json.JSONDecodeError:
|
31 |
+
log.error(f"Failed to parse JSON response: {response.text}")
|
|
|
|
|
|
|
|
|
|
|
32 |
return {"comments": [], "total_comments": 0}
|
33 |
|
34 |
comments_data = data.get("comments", [])
|
35 |
total_comments = data.get("total", 0)
|
36 |
|
37 |
if not comments_data:
|
38 |
+
log.warning(f"No comments found in response: {response.text}")
|
39 |
return {"comments": [], "total_comments": total_comments}
|
40 |
|
41 |
parsed_comments = []
|
|
|
52 |
async def scrape_comments(post_id: int, comments_count: int = 20, max_comments: int = None) -> List[Dict]:
|
53 |
|
54 |
def form_api_url(cursor: int):
|
55 |
+
base_url = "https://www.tiktok.com:8080/api/comment/list/?"
|
56 |
params = {
|
57 |
"aweme_id": post_id,
|
58 |
'count': comments_count,
|