Update app.py
Browse files
app.py
CHANGED
@@ -352,29 +352,6 @@ async def website_summarizer(url: str):
|
|
352 |
except Exception as e:
|
353 |
raise HTTPException(status_code=500, detail=f"Error during summarization: {e}")
|
354 |
|
355 |
-
@app.get("/api/website_summarizer2")
|
356 |
-
async def website_summarizer(url: str):
|
357 |
-
"""Summarizes the content of a given URL using a chat model."""
|
358 |
-
try:
|
359 |
-
# Extract text from the given URL
|
360 |
-
response = requests.get(url, headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0"})
|
361 |
-
response.raise_for_status()
|
362 |
-
visible_text = extract_text_from_webpage(response.text)
|
363 |
-
if len(visible_text) > 7500: # Adjust max_chars based on your needs
|
364 |
-
visible_text = visible_text[:7500] + "..."
|
365 |
-
|
366 |
-
# Use chat model to summarize the extracted text
|
367 |
-
with WEBS() as webs:
|
368 |
-
summary_prompt = f"Summarize this in detail in Paragraph: {visible_text}"
|
369 |
-
summary_result = webs.chat(keywords=summary_prompt, model="claude-3-haiku")
|
370 |
-
|
371 |
-
# Return the summary result
|
372 |
-
return JSONResponse(content=jsonable_encoder({summary_result}))
|
373 |
-
|
374 |
-
except requests.exceptions.RequestException as e:
|
375 |
-
raise HTTPException(status_code=500, detail=f"Error fetching or processing URL: {e}")
|
376 |
-
except Exception as e:
|
377 |
-
raise HTTPException(status_code=500, detail=f"Error during summarization: {e}")
|
378 |
@app.get("/api/ask_website")
|
379 |
async def ask_website(url: str, question: str, model: str = "llama-3-70b"):
|
380 |
"""
|
|
|
352 |
except Exception as e:
|
353 |
raise HTTPException(status_code=500, detail=f"Error during summarization: {e}")
|
354 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
355 |
@app.get("/api/ask_website")
|
356 |
async def ask_website(url: str, question: str, model: str = "llama-3-70b"):
|
357 |
"""
|