Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,6 @@ from pypdf import PdfReader
|
|
| 10 |
# 1. CONFIGURATION & LLM ENGINE
|
| 11 |
# -----------------------------
|
| 12 |
API_KEY = os.getenv("XAI_API_KEY")
|
| 13 |
-
# Current 2026 Production Endpoint
|
| 14 |
API_URL = "https://api.x.ai/v1/chat/completions"
|
| 15 |
MODEL_NAME = "grok-4-1-fast-non-reasoning"
|
| 16 |
|
|
@@ -54,16 +53,14 @@ def analyze_paper(url):
|
|
| 54 |
if not match:
|
| 55 |
return ["❌ Invalid URL. Please use a standard arXiv link."] + [""] * 8
|
| 56 |
paper_id = match.group(1)
|
| 57 |
-
|
| 58 |
-
# Fetch Metadata
|
| 59 |
search = arxiv.Search(id_list=[paper_id])
|
| 60 |
paper = next(search.results())
|
| 61 |
|
| 62 |
-
# Extract PDF Text (Targeting Intro, Math, and Conclusion)
|
| 63 |
resp = requests.get(paper.pdf_url)
|
| 64 |
reader = PdfReader(io.BytesIO(resp.content))
|
| 65 |
num_pages = len(reader.pages)
|
| 66 |
-
|
| 67 |
text_pages = [p.extract_text() for p in reader.pages[:7]]
|
| 68 |
if num_pages > 7:
|
| 69 |
text_pages.append(reader.pages[-1].extract_text())
|
|
@@ -73,11 +70,9 @@ def analyze_paper(url):
|
|
| 73 |
|
| 74 |
raw_analysis = call_grok(prompt)
|
| 75 |
|
| 76 |
-
# If API returned an error string, put it in the summary and exit
|
| 77 |
if "❌" in raw_analysis:
|
| 78 |
return [paper.title, raw_analysis] + [""] * 7
|
| 79 |
|
| 80 |
-
# Parsing logic
|
| 81 |
markers = ["SUMMARY", "PROBLEM", "IDEAS", "THEORY", "ALGO", "FINDINGS", "AUTHORS", "VERDICT"]
|
| 82 |
results = {}
|
| 83 |
for i, m in enumerate(markers):
|
|
@@ -95,8 +90,8 @@ def analyze_paper(url):
|
|
| 95 |
# 3. GRADIO UI
|
| 96 |
# -----------------------------
|
| 97 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="cyan"), title="arXivForMe Ultra") as demo:
|
| 98 |
-
gr.Markdown("# 🔬 arXivForMe
|
| 99 |
-
gr.Markdown("###
|
| 100 |
|
| 101 |
with gr.Row():
|
| 102 |
url_input = gr.Textbox(label="arXiv URL", placeholder="https://arxiv.org/abs/2401.12345", scale=4)
|
|
@@ -128,7 +123,6 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="cyan"), title="arXivForMe Ultra
|
|
| 128 |
with gr.Tab("⚖️ The Verdict"):
|
| 129 |
out_verd = gr.Markdown(label="AI Critical Opinion")
|
| 130 |
|
| 131 |
-
# Map function to UI components
|
| 132 |
outputs = [paper_display, out_sum, out_prob, out_idea, out_theo, out_algo, out_find, out_auth, out_verd]
|
| 133 |
run_btn.click(fn=analyze_paper, inputs=url_input, outputs=outputs)
|
| 134 |
|
|
|
|
| 10 |
# 1. CONFIGURATION & LLM ENGINE
|
| 11 |
# -----------------------------
|
| 12 |
API_KEY = os.getenv("XAI_API_KEY")
|
|
|
|
| 13 |
API_URL = "https://api.x.ai/v1/chat/completions"
|
| 14 |
MODEL_NAME = "grok-4-1-fast-non-reasoning"
|
| 15 |
|
|
|
|
| 53 |
if not match:
|
| 54 |
return ["❌ Invalid URL. Please use a standard arXiv link."] + [""] * 8
|
| 55 |
paper_id = match.group(1)
|
| 56 |
+
|
|
|
|
| 57 |
search = arxiv.Search(id_list=[paper_id])
|
| 58 |
paper = next(search.results())
|
| 59 |
|
|
|
|
| 60 |
resp = requests.get(paper.pdf_url)
|
| 61 |
reader = PdfReader(io.BytesIO(resp.content))
|
| 62 |
num_pages = len(reader.pages)
|
| 63 |
+
|
| 64 |
text_pages = [p.extract_text() for p in reader.pages[:7]]
|
| 65 |
if num_pages > 7:
|
| 66 |
text_pages.append(reader.pages[-1].extract_text())
|
|
|
|
| 70 |
|
| 71 |
raw_analysis = call_grok(prompt)
|
| 72 |
|
|
|
|
| 73 |
if "❌" in raw_analysis:
|
| 74 |
return [paper.title, raw_analysis] + [""] * 7
|
| 75 |
|
|
|
|
| 76 |
markers = ["SUMMARY", "PROBLEM", "IDEAS", "THEORY", "ALGO", "FINDINGS", "AUTHORS", "VERDICT"]
|
| 77 |
results = {}
|
| 78 |
for i, m in enumerate(markers):
|
|
|
|
| 90 |
# 3. GRADIO UI
|
| 91 |
# -----------------------------
|
| 92 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="cyan"), title="arXivForMe Ultra") as demo:
|
| 93 |
+
gr.Markdown("# 🔬 arXivForMe")
|
| 94 |
+
gr.Markdown("### Research Deconstruction Application*")
|
| 95 |
|
| 96 |
with gr.Row():
|
| 97 |
url_input = gr.Textbox(label="arXiv URL", placeholder="https://arxiv.org/abs/2401.12345", scale=4)
|
|
|
|
| 123 |
with gr.Tab("⚖️ The Verdict"):
|
| 124 |
out_verd = gr.Markdown(label="AI Critical Opinion")
|
| 125 |
|
|
|
|
| 126 |
outputs = [paper_display, out_sum, out_prob, out_idea, out_theo, out_algo, out_find, out_auth, out_verd]
|
| 127 |
run_btn.click(fn=analyze_paper, inputs=url_input, outputs=outputs)
|
| 128 |
|