| 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") |