Spaces:
Running
Running
improve llm prompt
Browse files- galis_app.py +2 -0
- llm/related_work_generator.py +45 -18
galis_app.py
CHANGED
|
@@ -114,6 +114,8 @@ def app():
|
|
| 114 |
with related_work_placeholder.container():
|
| 115 |
with st.spinner("Generating related work section..."):
|
| 116 |
related_work = generate_related_work(
|
|
|
|
|
|
|
| 117 |
st.session_state.references
|
| 118 |
)
|
| 119 |
st.session_state.related_work = related_work
|
|
|
|
| 114 |
with related_work_placeholder.container():
|
| 115 |
with st.spinner("Generating related work section..."):
|
| 116 |
related_work = generate_related_work(
|
| 117 |
+
st.session_state.abstract_title,
|
| 118 |
+
st.session_state.abstract_text,
|
| 119 |
st.session_state.references
|
| 120 |
)
|
| 121 |
st.session_state.related_work = related_work
|
llm/related_work_generator.py
CHANGED
|
@@ -16,12 +16,18 @@ logger = structlog.get_logger()
|
|
| 16 |
load_dotenv()
|
| 17 |
|
| 18 |
PROMPT_TEXT = """
|
| 19 |
-
You are a research assistant
|
| 20 |
-
for a research paper. You will be given a list of citations.
|
| 21 |
|
| 22 |
Your goal is to synthesize the provided citations into a coherent and well-structured "Related Work" section that
|
| 23 |
contextualizes the user's project within the existing academic literature.
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
**PROVIDED CITATIONS:**
|
| 26 |
{citations}
|
| 27 |
|
|
@@ -49,8 +55,12 @@ work introduces...", or "Building upon the foundation laid by [Author, Year], we
|
|
| 49 |
transitions between paragraphs and ideas to create a coherent narrative that logically leads the reader to understand
|
| 50 |
the novelty and importance of the user's project.
|
| 51 |
|
| 52 |
-
6. **
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
"""
|
| 55 |
|
| 56 |
|
|
@@ -67,12 +77,12 @@ def create_related_work_pipeline():
|
|
| 67 |
"""Creates a ready-to-use pipeline for generating the Related Work section."""
|
| 68 |
|
| 69 |
llm = ChatGoogleGenerativeAI(
|
| 70 |
-
model="gemini-
|
| 71 |
temperature=0.3
|
| 72 |
)
|
| 73 |
|
| 74 |
prompt = PromptTemplate(
|
| 75 |
-
input_variables=["citations"],
|
| 76 |
template=PROMPT_TEXT
|
| 77 |
)
|
| 78 |
|
|
@@ -83,24 +93,42 @@ def create_related_work_pipeline():
|
|
| 83 |
return chain
|
| 84 |
|
| 85 |
|
| 86 |
-
def generate_related_work(citations_text: str) -> str:
|
| 87 |
"""
|
| 88 |
-
Main function - pass citations, get Related Work
|
| 89 |
|
| 90 |
Args:
|
|
|
|
|
|
|
| 91 |
citations_text: Text with citations (can be a list or a string)
|
| 92 |
|
| 93 |
Returns:
|
| 94 |
The generated Related Work section
|
| 95 |
"""
|
| 96 |
pipeline = create_related_work_pipeline()
|
| 97 |
-
result = pipeline.invoke({
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
return result
|
| 99 |
|
| 100 |
|
| 101 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
|
| 104 |
Top 5 Citation Predictions:
|
| 105 |
- Title: 'deterministic construction of rip matrices in compressed sensing from constant weight codes'
|
| 106 |
- Title: 'mizar items exploring fine grained dependencies in the mizar mathematical library'
|
|
@@ -109,16 +137,15 @@ Top 5 Citation Predictions:
|
|
| 109 |
- Title: 'anonymization with worst case distribution based background knowledge'
|
| 110 |
"""
|
| 111 |
|
| 112 |
-
print("
|
| 113 |
-
print("
|
| 114 |
|
| 115 |
try:
|
| 116 |
-
related_work = generate_related_work(
|
| 117 |
print(related_work)
|
| 118 |
except Exception as e:
|
| 119 |
-
print(f"
|
| 120 |
-
print("
|
| 121 |
-
print("
|
| 122 |
-
print("
|
| 123 |
-
print("3. Uzyskaj klucz na: https://makersuite.google.com/app/apikey")
|
| 124 |
check_api_key()
|
|
|
|
| 16 |
load_dotenv()
|
| 17 |
|
| 18 |
PROMPT_TEXT = """
|
| 19 |
+
You are a research assistant specializing in academic writing. Your task is to generate a "Related Work" section
|
| 20 |
+
for a research paper. You will be given paper's title, abstract and a list of citations.
|
| 21 |
|
| 22 |
Your goal is to synthesize the provided citations into a coherent and well-structured "Related Work" section that
|
| 23 |
contextualizes the user's project within the existing academic literature.
|
| 24 |
|
| 25 |
+
**PROVIDED TITLE**
|
| 26 |
+
{title}
|
| 27 |
+
|
| 28 |
+
**PROVIDED ABSTRACT**
|
| 29 |
+
{abstract}**
|
| 30 |
+
|
| 31 |
**PROVIDED CITATIONS:**
|
| 32 |
{citations}
|
| 33 |
|
|
|
|
| 55 |
transitions between paragraphs and ideas to create a coherent narrative that logically leads the reader to understand
|
| 56 |
the novelty and importance of the user's project.
|
| 57 |
|
| 58 |
+
6. **Domain Sensitivity:** Adapt the discussion to the specific research domain indicated by the title and abstract.
|
| 59 |
+
Use appropriate terminology and focus on concepts, methods, and challenges relevant to that particular field of study.
|
| 60 |
+
|
| 61 |
+
7. **Output Format:** Generate only the text for the "Related Work" section. Do not include headers like
|
| 62 |
+
"INSTRUCTIONS," "PAPER TITLE," or "PROVIDED CITATIONS" in the final output. The entire response should be the
|
| 63 |
+
section text itself, ready to be inserted into an academic paper.
|
| 64 |
"""
|
| 65 |
|
| 66 |
|
|
|
|
| 77 |
"""Creates a ready-to-use pipeline for generating the Related Work section."""
|
| 78 |
|
| 79 |
llm = ChatGoogleGenerativeAI(
|
| 80 |
+
model="gemini-2.0-flash-exp",
|
| 81 |
temperature=0.3
|
| 82 |
)
|
| 83 |
|
| 84 |
prompt = PromptTemplate(
|
| 85 |
+
input_variables=["title", "abstract", "citations"],
|
| 86 |
template=PROMPT_TEXT
|
| 87 |
)
|
| 88 |
|
|
|
|
| 93 |
return chain
|
| 94 |
|
| 95 |
|
| 96 |
+
def generate_related_work(title:str, abstract:str, citations_text: str) -> str:
|
| 97 |
"""
|
| 98 |
+
Main function - pass title, abstract, and citations, get Related Work
|
| 99 |
|
| 100 |
Args:
|
| 101 |
+
title: The paper's title
|
| 102 |
+
abstract: The paper's abstract
|
| 103 |
citations_text: Text with citations (can be a list or a string)
|
| 104 |
|
| 105 |
Returns:
|
| 106 |
The generated Related Work section
|
| 107 |
"""
|
| 108 |
pipeline = create_related_work_pipeline()
|
| 109 |
+
result = pipeline.invoke({
|
| 110 |
+
"title": title,
|
| 111 |
+
"abstract": abstract,
|
| 112 |
+
"citations": citations_text
|
| 113 |
+
})
|
| 114 |
return result
|
| 115 |
|
| 116 |
|
| 117 |
if __name__ == "__main__":
|
| 118 |
+
title = "Privacy-Preserving Data Analysis in Distributed Systems: A Comprehensive Framework"
|
| 119 |
+
|
| 120 |
+
abstract = """
|
| 121 |
+
This paper presents a novel framework for privacy-preserving data analysis in distributed computing environments.
|
| 122 |
+
We propose a hybrid approach that combines differential privacy mechanisms with secure multi-party computation
|
| 123 |
+
to enable statistical analysis while maintaining strong privacy guarantees. Our framework addresses key challenges
|
| 124 |
+
in distributed data processing, including data heterogeneity, communication overhead, and scalability constraints.
|
| 125 |
+
Through extensive experiments on real-world datasets, we demonstrate that our approach achieves comparable accuracy
|
| 126 |
+
to centralized methods while providing provable privacy protection. The proposed system shows significant improvements
|
| 127 |
+
in computational efficiency compared to existing privacy-preserving solutions, making it practical for large-scale
|
| 128 |
+
deployment in enterprise environments.
|
| 129 |
+
"""
|
| 130 |
|
| 131 |
+
citations = """
|
| 132 |
Top 5 Citation Predictions:
|
| 133 |
- Title: 'deterministic construction of rip matrices in compressed sensing from constant weight codes'
|
| 134 |
- Title: 'mizar items exploring fine grained dependencies in the mizar mathematical library'
|
|
|
|
| 137 |
- Title: 'anonymization with worst case distribution based background knowledge'
|
| 138 |
"""
|
| 139 |
|
| 140 |
+
print("Generating Related Work...")
|
| 141 |
+
print("-" * 50)
|
| 142 |
|
| 143 |
try:
|
| 144 |
+
related_work = generate_related_work(title, abstract, citations)
|
| 145 |
print(related_work)
|
| 146 |
except Exception as e:
|
| 147 |
+
print(f"Error: {e}")
|
| 148 |
+
print("1. Create a .env file in the same folder as the script")
|
| 149 |
+
print("2. Add the line: GOOGLE_API_KEY=your_key")
|
| 150 |
+
print("3. Get the key at: https://makersuite.google.com/app/apikey")
|
|
|
|
| 151 |
check_api_key()
|