Spaces:
Running
on
T4
Running
on
T4
thomasht86
commited on
Upload main.py with huggingface_hub
Browse files
main.py
CHANGED
@@ -7,6 +7,7 @@ from concurrent.futures import ThreadPoolExecutor
|
|
7 |
from functools import partial
|
8 |
from pathlib import Path
|
9 |
import uuid
|
|
|
10 |
|
11 |
import google.generativeai as genai
|
12 |
from fasthtml.common import *
|
@@ -111,8 +112,9 @@ async def keepalive():
|
|
111 |
return
|
112 |
|
113 |
|
114 |
-
def generate_query_id(query):
|
115 |
-
|
|
|
116 |
|
117 |
|
118 |
@rt("/static/{filepath:path}")
|
@@ -121,7 +123,9 @@ def serve_static(filepath: str):
|
|
121 |
|
122 |
|
123 |
@rt("/")
|
124 |
-
def get():
|
|
|
|
|
125 |
return Layout(Main(Home()))
|
126 |
|
127 |
|
@@ -156,7 +160,10 @@ def get(session, request):
|
|
156 |
)
|
157 |
)
|
158 |
# Generate a unique query_id based on the query and ranking value
|
159 |
-
|
|
|
|
|
|
|
160 |
query_id = session.get("query_id")
|
161 |
print(f"Query id in /search: {query_id}")
|
162 |
# Show the loading message if a query is provided
|
@@ -180,6 +187,11 @@ async def get(session, request, query: str, nn: bool = True):
|
|
180 |
f"/fetch_results: Fetching results for query: {query}, ranking: {ranking_value}"
|
181 |
)
|
182 |
# Generate a unique query_id based on the query and ranking value
|
|
|
|
|
|
|
|
|
|
|
183 |
query_id = session.get("query_id")
|
184 |
print(f"Query id in /fetch_results: {query_id}")
|
185 |
# Run the embedding and query against Vespa app
|
|
|
7 |
from functools import partial
|
8 |
from pathlib import Path
|
9 |
import uuid
|
10 |
+
import hashlib
|
11 |
|
12 |
import google.generativeai as genai
|
13 |
from fasthtml.common import *
|
|
|
112 |
return
|
113 |
|
114 |
|
115 |
+
def generate_query_id(session_id, query, ranking_value):
|
116 |
+
hash_input = (session_id + query + ranking_value).encode("utf-8")
|
117 |
+
return hashlib.sha256(hash_input).hexdigest()
|
118 |
|
119 |
|
120 |
@rt("/static/{filepath:path}")
|
|
|
123 |
|
124 |
|
125 |
@rt("/")
|
126 |
+
def get(session):
|
127 |
+
if "session_id" not in session:
|
128 |
+
session["session_id"] = str(uuid.uuid4())
|
129 |
return Layout(Main(Home()))
|
130 |
|
131 |
|
|
|
160 |
)
|
161 |
)
|
162 |
# Generate a unique query_id based on the query and ranking value
|
163 |
+
if "query_id" not in session:
|
164 |
+
session["query_id"] = generate_query_id(
|
165 |
+
session["session_id"], query_value, ranking_value
|
166 |
+
)
|
167 |
query_id = session.get("query_id")
|
168 |
print(f"Query id in /search: {query_id}")
|
169 |
# Show the loading message if a query is provided
|
|
|
187 |
f"/fetch_results: Fetching results for query: {query}, ranking: {ranking_value}"
|
188 |
)
|
189 |
# Generate a unique query_id based on the query and ranking value
|
190 |
+
print(f"Sesssion in /fetch_results: {session}")
|
191 |
+
if "query_id" not in session:
|
192 |
+
session["query_id"] = generate_query_id(
|
193 |
+
session["session_id"], query_value, ranking_value
|
194 |
+
)
|
195 |
query_id = session.get("query_id")
|
196 |
print(f"Query id in /fetch_results: {query_id}")
|
197 |
# Run the embedding and query against Vespa app
|