BoojithDharshan commited on
Commit
6c926cd
·
verified ·
1 Parent(s): 6a52478

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pdfplumber
3
+ import openai
4
+ import os
5
+
6
+ # Set your OpenAI API key (set it in Hugging Face Secrets for security)
7
+ openai.api_key = os.getenv("AIzaSyB9xXfstwZf8htC-lTjD3nwCHChbh-zWtg")
8
+ client = openai.OpenAI()
9
+
10
+ def analyze_pdf(pdf_file):
11
+ # Extract text from PDF
12
+ with pdfplumber.open(pdf_file) as pdf:
13
+ text = "\n".join([page.extract_text() or "" for page in pdf.pages])
14
+
15
+ if not text.strip():
16
+ return "No readable text found in the PDF."
17
+
18
+ # Build the prompt
19
+ prompt = f"""Analyze the following research paper content:
20
+ {text}
21
+ Please:
22
+ 1. Summarize each section of the paper.
23
+ 2. Identify any potential research gaps.
24
+ 3. Provide constructive suggestions for improving the paper."""
25
+
26
+ # Send to OpenAI
27
+ response = client.chat.completions.create(
28
+ model="gpt-3.5-turbo", # or "gpt-4"
29
+ messages=[
30
+ {"role": "user", "content": prompt}
31
+ ],
32
+ temperature=0.7,
33
+ max_tokens=2000
34
+ )
35
+
36
+ result = response.choices[0].message.content
37
+ return result
38
+
39
+ # Gradio UI
40
+ iface = gr.Interface(
41
+ fn=analyze_pdf,
42
+ inputs=gr.File(label="Upload Research Paper (PDF)", file_types=[".pdf"]),
43
+ outputs=gr.Textbox(label="Critique Output", lines=30),
44
+ title="🧠 Research Paper Critique Generator",
45
+ description="Upload a research paper PDF to get summaries, research gaps, and improvement suggestions using GPT."
46
+ )
47
+
48
+ iface.launch()