File size: 2,158 Bytes
e180ad6
 
 
79188ac
 
 
 
fcba8d7
79188ac
 
e180ad6
 
 
 
 
 
 
4b7a92a
446070b
e180ad6
 
 
 
 
 
 
4b7a92a
e180ad6
4b7a92a
e180ad6
 
79188ac
e180ad6
 
 
 
4b7a92a
 
568cf71
e180ad6
 
 
 
 
 
 
 
 
 
 
4b7a92a
e180ad6
 
4b7a92a
e180ad6
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pdfplumber
from groq import Groq
import os
from dotenv import load_dotenv

load_dotenv()

api = os.getenv("groq_api_key")

def extract_text_from_pdf(pdf_file):
    text = ""
    with pdfplumber.open(pdf_file) as pdf:
        for page in pdf.pages:
            content=page.extract_text() + "\n"
            client = Groq(api_key=api,)
            chat_completion=client.chat.completions.create(
            messages=[{"role": "system", "content": "Summarize the page and mainly keep the headings and topic names intact in the short summary."},
                      {"role": "user","content": "Summarize and mainly keep the headings and name of topics in summary:"+content,}],
            model="llama3-8b-8192",
            )
            text += chat_completion.choices[0].message.content
    return text


from groq import Groq
import os
def study_planner(file):
    if file is None:
        return "Please upload a valid file."

    try:
        study_material = extract_text_from_pdf(file.name)

        client = Groq(api_key=api,)

        chat_completion = client.chat.completions.create(
            messages=[{"role": "system", "content": "Provided a short summary or precisely,a list of topics and headings present in the paper,give a study plan to study the paper effectively.You should include essential prerequisites for the topics also in the plan."},
                      {"role": "user","content": "The summary or list of headings in the paper is:"+study_material+".Now give the desiered study plan with essential prerequisites.",}],
            model="llama3-70b-8192",
            )
        study_plan = chat_completion.choices[0].message.content
        """pdf_path = text_to_pdf(study_plan)"""
        return study_plan
    except Exception as e:
        return f"An error occurred while processing the file: {str(e)}"


import gradio as gr
demo = gr.Interface(
    fn=study_planner,
    inputs=gr.File(label="Upload the research paper (PDF)"),
    outputs=gr.Textbox(label="Optimum study plan"),
    title="Research Paper Study Planner",
    description="Upload the research paper to get a study plan"
)

demo.launch(share="True")