Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,33 @@
|
|
|
|
1 |
import os
|
|
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
import pandas as pd
|
5 |
from typing import Tuple
|
6 |
|
7 |
|
|
|
|
|
|
|
|
|
8 |
def search_stories(query: str, page: int) -> Tuple[pd.DataFrame, int]:
|
9 |
"""
|
10 |
Search stories from local API and return results as DataFrame
|
11 |
"""
|
12 |
try:
|
13 |
-
response =
|
14 |
url=os.environ.get("API_URL", "http://50.18.255.74:8600/search"),
|
15 |
json={"query": query, "page": page},
|
16 |
-
headers={
|
|
|
|
|
|
|
17 |
)
|
18 |
response.raise_for_status()
|
19 |
-
|
|
|
20 |
# Convert response data to DataFrame
|
21 |
-
data = response.json()["hits"]
|
22 |
df = pd.DataFrame(data)
|
23 |
|
24 |
# Reorder columns for better display
|
|
|
1 |
+
import json
|
2 |
import os
|
3 |
+
import gzip
|
4 |
import gradio as gr
|
5 |
import requests
|
6 |
import pandas as pd
|
7 |
from typing import Tuple
|
8 |
|
9 |
|
10 |
+
client_session = requests.Session()
|
11 |
+
client_session.keep_alive = 5
|
12 |
+
|
13 |
+
|
14 |
def search_stories(query: str, page: int) -> Tuple[pd.DataFrame, int]:
|
15 |
"""
|
16 |
Search stories from local API and return results as DataFrame
|
17 |
"""
|
18 |
try:
|
19 |
+
response = client_session.post(
|
20 |
url=os.environ.get("API_URL", "http://50.18.255.74:8600/search"),
|
21 |
json={"query": query, "page": page},
|
22 |
+
headers={
|
23 |
+
"Content-Type": "application/json",
|
24 |
+
"Accept-Encoding": "gzip",
|
25 |
+
},
|
26 |
)
|
27 |
response.raise_for_status()
|
28 |
+
data = response.content
|
29 |
+
data = json.loads(data)["hits"]
|
30 |
# Convert response data to DataFrame
|
|
|
31 |
df = pd.DataFrame(data)
|
32 |
|
33 |
# Reorder columns for better display
|