Update app.py
Browse files
app.py
CHANGED
@@ -482,7 +482,7 @@ def display_results(data):
|
|
482 |
# Add the generate_literature_survey function below your other function definitions
|
483 |
def generate_literature_survey(papers, api_key="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"):
|
484 |
"""
|
485 |
-
Generate a literature survey based on paper abstracts using Groq API with Llama-3.3-70B-
|
486 |
|
487 |
Parameters:
|
488 |
papers (list): List of papers with abstracts
|
@@ -491,19 +491,16 @@ def generate_literature_survey(papers, api_key="gsk_G80LBPxmvDjQZ77zX0FIWGdyb3FY
|
|
491 |
Returns:
|
492 |
str: Generated literature survey
|
493 |
"""
|
494 |
-
# Check if we have papers with abstracts
|
495 |
if not papers or len(papers) == 0:
|
496 |
return "No papers found to generate a literature survey."
|
497 |
|
498 |
-
# Filter papers that have abstracts
|
499 |
papers_with_abstracts = [p for p in papers if p.get("Abstract") and len(p.get("Abstract")) > 50]
|
500 |
|
501 |
if len(papers_with_abstracts) == 0:
|
502 |
return "Cannot generate a literature survey because none of the papers have substantial abstracts."
|
503 |
|
504 |
-
# Construct the prompt for the LLM
|
505 |
paper_info = []
|
506 |
-
for i, paper in enumerate(papers_with_abstracts[:10]):
|
507 |
paper_info.append(f"Paper {i+1}:\nTitle: {paper.get('Title', 'Unknown')}\nAuthors: {paper.get('Author(s)', 'Unknown')}\nYear: {paper.get('Published', 'Unknown')}\nAbstract: {paper.get('Abstract', 'No abstract available')}\n")
|
508 |
|
509 |
papers_text = "\n".join(paper_info)
|
@@ -515,24 +512,20 @@ write a concise literature survey that:
|
|
515 |
3. Summarizes key findings
|
516 |
4. Points out research gaps if evident
|
517 |
5. Suggests potential future research directions
|
518 |
-
|
519 |
Here are the papers:
|
520 |
-
|
521 |
{papers_text}
|
522 |
-
|
523 |
Please organize the survey by themes rather than by individual papers, creating connections between studies.
|
524 |
Format your response with markdown headings for better readability.
|
525 |
"""
|
526 |
|
527 |
-
|
528 |
-
url = "https://api.groq.com/openai/v1/chat/completions"
|
529 |
headers = {
|
530 |
"Authorization": f"Bearer {api_key}",
|
531 |
"Content-Type": "application/json"
|
532 |
}
|
533 |
|
534 |
data = {
|
535 |
-
"model": "
|
536 |
"messages": [
|
537 |
{"role": "system", "content": "You are an academic research assistant that creates comprehensive literature surveys."},
|
538 |
{"role": "user", "content": prompt}
|
@@ -548,9 +541,15 @@ Format your response with markdown headings for better readability.
|
|
548 |
survey_text = result["choices"][0]["message"]["content"]
|
549 |
return survey_text
|
550 |
except Exception as e:
|
551 |
-
st.error(f"Error generating literature survey: {e}")
|
552 |
return f"Failed to generate literature survey due to an error: {str(e)}"
|
553 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
554 |
# Add the add_literature_survey_button function
|
555 |
def add_literature_survey_button(search_results_df):
|
556 |
"""
|
|
|
482 |
# Add the generate_literature_survey function below your other function definitions
|
483 |
def generate_literature_survey(papers, api_key="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"):
|
484 |
"""
|
485 |
+
Generate a literature survey based on paper abstracts using Groq API with Llama-3.3-70B-Versatile
|
486 |
|
487 |
Parameters:
|
488 |
papers (list): List of papers with abstracts
|
|
|
491 |
Returns:
|
492 |
str: Generated literature survey
|
493 |
"""
|
|
|
494 |
if not papers or len(papers) == 0:
|
495 |
return "No papers found to generate a literature survey."
|
496 |
|
|
|
497 |
papers_with_abstracts = [p for p in papers if p.get("Abstract") and len(p.get("Abstract")) > 50]
|
498 |
|
499 |
if len(papers_with_abstracts) == 0:
|
500 |
return "Cannot generate a literature survey because none of the papers have substantial abstracts."
|
501 |
|
|
|
502 |
paper_info = []
|
503 |
+
for i, paper in enumerate(papers_with_abstracts[:10]):
|
504 |
paper_info.append(f"Paper {i+1}:\nTitle: {paper.get('Title', 'Unknown')}\nAuthors: {paper.get('Author(s)', 'Unknown')}\nYear: {paper.get('Published', 'Unknown')}\nAbstract: {paper.get('Abstract', 'No abstract available')}\n")
|
505 |
|
506 |
papers_text = "\n".join(paper_info)
|
|
|
512 |
3. Summarizes key findings
|
513 |
4. Points out research gaps if evident
|
514 |
5. Suggests potential future research directions
|
|
|
515 |
Here are the papers:
|
|
|
516 |
{papers_text}
|
|
|
517 |
Please organize the survey by themes rather than by individual papers, creating connections between studies.
|
518 |
Format your response with markdown headings for better readability.
|
519 |
"""
|
520 |
|
521 |
+
url = "https://api.groq.com/v1/chat/completions" # Updated endpoint
|
|
|
522 |
headers = {
|
523 |
"Authorization": f"Bearer {api_key}",
|
524 |
"Content-Type": "application/json"
|
525 |
}
|
526 |
|
527 |
data = {
|
528 |
+
"model": "llama-70b", # Adjust this based on Groq's available models
|
529 |
"messages": [
|
530 |
{"role": "system", "content": "You are an academic research assistant that creates comprehensive literature surveys."},
|
531 |
{"role": "user", "content": prompt}
|
|
|
541 |
survey_text = result["choices"][0]["message"]["content"]
|
542 |
return survey_text
|
543 |
except Exception as e:
|
|
|
544 |
return f"Failed to generate literature survey due to an error: {str(e)}"
|
545 |
|
546 |
+
# Example usage
|
547 |
+
papers = [
|
548 |
+
{"Title": "Sample Paper", "Author(s)": "John Doe", "Published": "2023", "Abstract": "This is a sample abstract with more than 50 characters to test the function."}
|
549 |
+
]
|
550 |
+
survey = generate_literature_survey(papers, api_key="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")
|
551 |
+
print(survey)
|
552 |
+
|
553 |
# Add the add_literature_survey_button function
|
554 |
def add_literature_survey_button(search_results_df):
|
555 |
"""
|