Spaces:
Sleeping
Sleeping
Update backend/main.py
Browse files- backend/main.py +5 -5
backend/main.py
CHANGED
|
@@ -179,8 +179,8 @@ def extract_text_from_pdf(pdf_path: str) -> str:
|
|
| 179 |
text = text[chars // 10: chars // 10 + 15000]
|
| 180 |
|
| 181 |
words = text.split()
|
| 182 |
-
if len(words) >
|
| 183 |
-
text = " ".join(words[:
|
| 184 |
|
| 185 |
text = text.replace("\n", " ")
|
| 186 |
|
|
@@ -220,7 +220,7 @@ def parse_json_response(raw: str) -> dict:
|
|
| 220 |
|
| 221 |
|
| 222 |
def call_groq_with_backoff(client: Groq, messages: list) -> str:
|
| 223 |
-
word_limits = [
|
| 224 |
attempt = 0
|
| 225 |
while attempt < len(word_limits):
|
| 226 |
try:
|
|
@@ -228,7 +228,7 @@ def call_groq_with_backoff(client: Groq, messages: list) -> str:
|
|
| 228 |
model=GROQ_MODEL,
|
| 229 |
messages=messages,
|
| 230 |
temperature=0.1,
|
| 231 |
-
max_tokens=
|
| 232 |
)
|
| 233 |
return response.choices[0].message.content
|
| 234 |
except Exception as e:
|
|
@@ -272,7 +272,7 @@ def compare_protocols(client: Groq, extracted: list, paper_names: list) -> dict:
|
|
| 272 |
for i, (e, name) in enumerate(zip(extracted, paper_names)):
|
| 273 |
sections.append(
|
| 274 |
f"=== Paper {i+1}: {e.get('title', name)} ===\n"
|
| 275 |
-
f"{json.dumps(e.get('parameters', {}))
|
| 276 |
)
|
| 277 |
prompt = (
|
| 278 |
f"Compare these {len(extracted)} research paper protocols "
|
|
|
|
| 179 |
text = text[chars // 10: chars // 10 + 15000]
|
| 180 |
|
| 181 |
words = text.split()
|
| 182 |
+
if len(words) > 1500:
|
| 183 |
+
text = " ".join(words[:1500])
|
| 184 |
|
| 185 |
text = text.replace("\n", " ")
|
| 186 |
|
|
|
|
| 220 |
|
| 221 |
|
| 222 |
def call_groq_with_backoff(client: Groq, messages: list) -> str:
|
| 223 |
+
word_limits = [2500, 2000, 1500, 1000]
|
| 224 |
attempt = 0
|
| 225 |
while attempt < len(word_limits):
|
| 226 |
try:
|
|
|
|
| 228 |
model=GROQ_MODEL,
|
| 229 |
messages=messages,
|
| 230 |
temperature=0.1,
|
| 231 |
+
max_tokens=2000,
|
| 232 |
)
|
| 233 |
return response.choices[0].message.content
|
| 234 |
except Exception as e:
|
|
|
|
| 272 |
for i, (e, name) in enumerate(zip(extracted, paper_names)):
|
| 273 |
sections.append(
|
| 274 |
f"=== Paper {i+1}: {e.get('title', name)} ===\n"
|
| 275 |
+
f"{json.dumps(e.get('parameters', {}), indent=2)}"
|
| 276 |
)
|
| 277 |
prompt = (
|
| 278 |
f"Compare these {len(extracted)} research paper protocols "
|