Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import pdfplumber | |
| import openai | |
| import os | |
| # Set your OpenAI API key (set it in Hugging Face Secrets for security) | |
| openai.api_key = os.getenv("AIzaSyB9xXfstwZf8htC-lTjD3nwCHChbh-zWtg") | |
| client = openai.OpenAI() | |
| def analyze_pdf(pdf_file): | |
| # Extract text from PDF | |
| with pdfplumber.open(pdf_file) as pdf: | |
| text = "\n".join([page.extract_text() or "" for page in pdf.pages]) | |
| if not text.strip(): | |
| return "No readable text found in the PDF." | |
| # Build the prompt | |
| prompt = f"""Analyze the following research paper content: | |
| {text} | |
| Please: | |
| 1. Summarize each section of the paper. | |
| 2. Identify any potential research gaps. | |
| 3. Provide constructive suggestions for improving the paper.""" | |
| # Send to OpenAI | |
| response = client.chat.completions.create( | |
| model="gpt-3.5-turbo", # or "gpt-4" | |
| messages=[ | |
| {"role": "user", "content": prompt} | |
| ], | |
| temperature=0.7, | |
| max_tokens=2000 | |
| ) | |
| result = response.choices[0].message.content | |
| return result | |
| # Gradio UI | |
| iface = gr.Interface( | |
| fn=analyze_pdf, | |
| inputs=gr.File(label="Upload Research Paper (PDF)", file_types=[".pdf"]), | |
| outputs=gr.Textbox(label="Critique Output", lines=30), | |
| title="🧠 Research Paper Critique Generator", | |
| description="Upload a research paper PDF to get summaries, research gaps, and improvement suggestions using GPT." | |
| ) | |
| iface.launch() | |