Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -55,26 +55,28 @@ def identify_research_gaps():
|
|
55 |
for j, chunk_2 in enumerate(metadata_store):
|
56 |
if i >= j: # Avoid duplicate comparisons
|
57 |
continue
|
58 |
-
# Simple comparison: finding contradictions or lack of mentions
|
59 |
if "not" in chunk_1["chunk"] and "is" in chunk_2["chunk"]:
|
60 |
gap_summary.append(f"Potential contradiction between chunks {i} and {j}")
|
61 |
return gap_summary
|
62 |
|
63 |
def ask_groq_api(question, context):
|
64 |
chat_completion = client.chat.completions.create(
|
65 |
-
messages=[
|
66 |
-
{"role": "user", "content": f"{context}\n\n{question}"}
|
67 |
-
],
|
68 |
model="llama3-8b-8192"
|
69 |
)
|
70 |
return chat_completion.choices[0].message.content
|
71 |
|
72 |
# Streamlit App
|
73 |
-
st.
|
74 |
|
75 |
-
|
|
|
|
|
|
|
76 |
|
77 |
if uploaded_files:
|
|
|
|
|
78 |
all_chunks = []
|
79 |
all_metadata = []
|
80 |
|
@@ -86,14 +88,14 @@ if uploaded_files:
|
|
86 |
store_embeddings(embeddings, metadata)
|
87 |
all_chunks.extend(chunks)
|
88 |
all_metadata.extend(metadata)
|
89 |
-
|
90 |
-
st.success("Files uploaded and processed successfully!")
|
91 |
|
92 |
-
|
|
|
|
|
93 |
for chunk in all_chunks[:3]:
|
94 |
-
st.write(chunk)
|
95 |
|
96 |
-
user_question = st.text_input("Ask a question about the uploaded papers:")
|
97 |
if user_question:
|
98 |
relevant_chunks = retrieve_relevant_chunks(user_question)
|
99 |
if relevant_chunks:
|
@@ -101,19 +103,19 @@ if uploaded_files:
|
|
101 |
answer = ask_groq_api(user_question, context)
|
102 |
st.write("**Answer:**", answer)
|
103 |
else:
|
104 |
-
st.write("No relevant sections found for your question.")
|
105 |
|
106 |
-
if st.button("Identify Research Gaps"):
|
107 |
research_gaps = identify_research_gaps()
|
108 |
if research_gaps:
|
109 |
-
st.write("### Research Gaps Identified:")
|
110 |
for gap in research_gaps:
|
111 |
-
st.write(f"
|
112 |
else:
|
113 |
-
st.write("No significant research gaps identified.")
|
114 |
|
115 |
-
if st.button("Generate Scatter Plot"):
|
116 |
-
st.write("Generating scatter plot for methods vs. results...")
|
117 |
# Example scatter plot (replace with real data)
|
118 |
x = np.random.rand(10)
|
119 |
y = np.random.rand(10)
|
@@ -122,4 +124,4 @@ if uploaded_files:
|
|
122 |
plt.ylabel("Results")
|
123 |
st.pyplot(plt)
|
124 |
|
125 |
-
st.text_area("Annotate Your Insights:", height=100, key="annotations")
|
|
|
55 |
for j, chunk_2 in enumerate(metadata_store):
|
56 |
if i >= j: # Avoid duplicate comparisons
|
57 |
continue
|
|
|
58 |
if "not" in chunk_1["chunk"] and "is" in chunk_2["chunk"]:
|
59 |
gap_summary.append(f"Potential contradiction between chunks {i} and {j}")
|
60 |
return gap_summary
|
61 |
|
62 |
def ask_groq_api(question, context):
|
63 |
chat_completion = client.chat.completions.create(
|
64 |
+
messages=[{"role": "user", "content": f"{context}\n\n{question}"}],
|
|
|
|
|
65 |
model="llama3-8b-8192"
|
66 |
)
|
67 |
return chat_completion.choices[0].message.content
|
68 |
|
69 |
# Streamlit App
|
70 |
+
st.set_page_config(page_title="Research Analyzer", page_icon="π")
|
71 |
|
72 |
+
st.title("π Research Paper Analyzer with Gap Identification")
|
73 |
+
st.write("Easily analyze and identify gaps in your research papers. π§ ")
|
74 |
+
|
75 |
+
uploaded_files = st.file_uploader("π€ Upload PDF Files", accept_multiple_files=True, type="pdf")
|
76 |
|
77 |
if uploaded_files:
|
78 |
+
st.success("π Files uploaded successfully! Processing...")
|
79 |
+
|
80 |
all_chunks = []
|
81 |
all_metadata = []
|
82 |
|
|
|
88 |
store_embeddings(embeddings, metadata)
|
89 |
all_chunks.extend(chunks)
|
90 |
all_metadata.extend(metadata)
|
|
|
|
|
91 |
|
92 |
+
st.success("β
Files processed and embeddings created!")
|
93 |
+
|
94 |
+
if st.button("π View Topic Summaries"):
|
95 |
for chunk in all_chunks[:3]:
|
96 |
+
st.write("πΉ", chunk)
|
97 |
|
98 |
+
user_question = st.text_input("β Ask a question about the uploaded papers:")
|
99 |
if user_question:
|
100 |
relevant_chunks = retrieve_relevant_chunks(user_question)
|
101 |
if relevant_chunks:
|
|
|
103 |
answer = ask_groq_api(user_question, context)
|
104 |
st.write("**Answer:**", answer)
|
105 |
else:
|
106 |
+
st.write("β οΈ No relevant sections found for your question.")
|
107 |
|
108 |
+
if st.button("π Identify Research Gaps"):
|
109 |
research_gaps = identify_research_gaps()
|
110 |
if research_gaps:
|
111 |
+
st.write("### π οΈ Research Gaps Identified:")
|
112 |
for gap in research_gaps:
|
113 |
+
st.write(f"πΈ {gap}")
|
114 |
else:
|
115 |
+
st.write("β
No significant research gaps identified.")
|
116 |
|
117 |
+
if st.button("π Generate Scatter Plot"):
|
118 |
+
st.write("π Generating scatter plot for methods vs. results...")
|
119 |
# Example scatter plot (replace with real data)
|
120 |
x = np.random.rand(10)
|
121 |
y = np.random.rand(10)
|
|
|
124 |
plt.ylabel("Results")
|
125 |
st.pyplot(plt)
|
126 |
|
127 |
+
st.text_area("π Annotate Your Insights:", height=100, key="annotations")
|