Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -442,6 +442,51 @@ if st.button("Ask"):
|
|
442 |
except Exception as e:
|
443 |
st.error(f"Follow-up error: {e}")
|
444 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
445 |
# --- Optional: View Chat History ---
|
446 |
with st.expander("π View Full Chat History", expanded=False):
|
447 |
for msg in st.session_state.chat_history:
|
|
|
442 |
except Exception as e:
|
443 |
st.error(f"Follow-up error: {e}")
|
444 |
|
445 |
+
# --- Paper Upload for Review & Improvement ---
|
446 |
+
st.divider()
|
447 |
+
st.subheader("π€ Upload Your Paper for Feedback")
|
448 |
+
|
449 |
+
uploaded_file = st.file_uploader("Upload your research paper (.pdf or .txt)", type=["pdf", "txt"])
|
450 |
+
|
451 |
+
if uploaded_file and st.button("π§ Analyze and Suggest Improvements"):
|
452 |
+
try:
|
453 |
+
def extract_text_from_file(file):
|
454 |
+
if file.name.endswith(".pdf"):
|
455 |
+
from PyPDF2 import PdfReader
|
456 |
+
reader = PdfReader(file)
|
457 |
+
return "\n".join([page.extract_text() for page in reader.pages if page.extract_text()])
|
458 |
+
elif file.name.endswith(".txt"):
|
459 |
+
return file.read().decode("utf-8")
|
460 |
+
return ""
|
461 |
+
|
462 |
+
paper_text = extract_text_from_file(uploaded_file)
|
463 |
+
|
464 |
+
if not paper_text or len(paper_text.strip()) < 100:
|
465 |
+
st.warning("β οΈ The uploaded paper seems empty or too short to analyze.")
|
466 |
+
else:
|
467 |
+
feedback_prompt = [
|
468 |
+
{"role": "system", "content": "You are an expert academic advisor."},
|
469 |
+
{"role": "user", "content": f"""I have written the following research paper. Please analyze it and provide detailed suggestions on:
|
470 |
+
- Areas where the paper is weak or unclear
|
471 |
+
- How to improve the novelty or originality
|
472 |
+
- Structural improvements or better ways to present arguments
|
473 |
+
|
474 |
+
Be honest and constructive. Here's the full text:
|
475 |
+
|
476 |
+
\"\"\"{paper_text}\"\"\""""}
|
477 |
+
]
|
478 |
+
|
479 |
+
with st.status("π Analyzing your paper..."):
|
480 |
+
improvement_output = ""
|
481 |
+
feedback_box = st.empty()
|
482 |
+
for chunk in call_llm(feedback_prompt, max_tokens=2500):
|
483 |
+
improvement_output += chunk
|
484 |
+
feedback_box.markdown(improvement_output, unsafe_allow_html=True)
|
485 |
+
|
486 |
+
except Exception as e:
|
487 |
+
st.error(f"β Error while analyzing paper: {e}")
|
488 |
+
|
489 |
+
|
490 |
# --- Optional: View Chat History ---
|
491 |
with st.expander("π View Full Chat History", expanded=False):
|
492 |
for msg in st.session_state.chat_history:
|