import gradio as gr import openai import fitz # PyMuPDF import os import tempfile # API Key input and status def set_api_key(api_key): if api_key: openai.api_key = api_key return "API Key Set" else: return "API Key not set" # PDF text extraction function def extract_text_from_pdf(pdf_file): try: with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_file: tmp_file.write(pdf_file.read()) tmp_file_path = tmp_file.name doc = fitz.open(tmp_file_path) text = "\n".join([page.get_text("text") for page in doc]) doc.close() os.remove(tmp_file_path) return text except Exception as e: return f"Error extracting text: {e}" # Review generator function def generate_review(api_key, uploaded_files, review_question, include_tables): if not api_key: return "Please enter your OpenAI API key." if not uploaded_files: return "Please upload at least one PDF file." if not review_question: return "Please enter a review question." # File type validation: check if all uploaded files are PDFs for file in uploaded_files: if not file.name.lower().endswith('.pdf'): return f"Invalid file type. Please upload a PDF file, but '{file.name}' is not a PDF." system_prompt = """ You are an expert academic assistant. Create a systematic review in HTML format using

,

,

,