Spaces:
Sleeping
Sleeping
Update sherlock2.py
Browse files- sherlock2.py +6 -42
sherlock2.py
CHANGED
@@ -110,22 +110,6 @@ def process_images(uploaded_images):
|
|
110 |
st.error(f"Error processing image: {e}")
|
111 |
return image_insights
|
112 |
|
113 |
-
class WikipediaSearcher:
|
114 |
-
def __init__(self):
|
115 |
-
self._search_history = []
|
116 |
-
self._search_urls = []
|
117 |
-
|
118 |
-
def search(self, query):
|
119 |
-
"""Performs a Wikipedia search and returns relevant information."""
|
120 |
-
try:
|
121 |
-
summary = wikipedia.summary(query, sentences=3, auto_suggest=False)
|
122 |
-
wiki_url = wikipedia.page(query, auto_suggest=False).url
|
123 |
-
self._search_history.append(query)
|
124 |
-
self._search_urls.append(wiki_url)
|
125 |
-
return f"**Summary:** {summary}\n**URL:** {wiki_url}"
|
126 |
-
except (DisambiguationError, PageError) as e:
|
127 |
-
return f"Could not find information on '{query}' in Wikipedia."
|
128 |
-
|
129 |
def search_internet(case_text):
|
130 |
"""Generates search queries using Gemini 1.5 Pro and performs internet searches for case-related information."""
|
131 |
prompt = """
|
@@ -178,7 +162,7 @@ def clear_chat():
|
|
178 |
st.session_state.chat_history = []
|
179 |
|
180 |
def investigate():
|
181 |
-
"""Handles the case investigation process with Pandas for embeddings
|
182 |
st.subheader("Case Investigation")
|
183 |
|
184 |
# File upload with clear labels and progress bars
|
@@ -206,20 +190,6 @@ def investigate():
|
|
206 |
"keywords": keywords
|
207 |
}
|
208 |
|
209 |
-
# --- Wikipedia Search using Keywords ---
|
210 |
-
wikipedia_searcher = WikipediaSearcher()
|
211 |
-
wikipedia_results = []
|
212 |
-
with st.spinner("Searching Wikipedia using keywords..."):
|
213 |
-
for keyword in keywords:
|
214 |
-
result = wikipedia_searcher.search(keyword)
|
215 |
-
wikipedia_results.append(result)
|
216 |
-
|
217 |
-
# Display Wikipedia search results
|
218 |
-
st.subheader("Wikipedia Search Results (Based on Keywords):")
|
219 |
-
for result in wikipedia_results:
|
220 |
-
st.write(result)
|
221 |
-
|
222 |
-
# --- Prompt Generation and Sherlock's Analysis ---
|
223 |
prompt = """
|
224 |
You are Sherlock Holmes, the renowned detective. Analyze the following case information and provide insights or
|
225 |
suggestions for further investigation:
|
@@ -231,7 +201,6 @@ def investigate():
|
|
231 |
with st.expander("Sherlock's Analysis and Suggestions:"):
|
232 |
st.write(response.text)
|
233 |
|
234 |
-
# --- Web Search ---
|
235 |
web_search_results = []
|
236 |
|
237 |
search_options = st.multiselect("Search for additional clues:", ["Internet"], default=["Internet"])
|
@@ -244,21 +213,16 @@ def investigate():
|
|
244 |
st.write(f"**Snippet:** {result['snippet']}")
|
245 |
st.write(f"**URL:** {result['url']}")
|
246 |
|
247 |
-
#
|
248 |
if st.button("Generate Case Report"):
|
249 |
with st.spinner("Generating report..."):
|
250 |
report_prompt = """
|
251 |
You are Sherlock Holmes, the renowned detective. Based on the case information, your analysis, findings from
|
252 |
-
the web
|
253 |
including deductions, potential suspects, and conclusions.
|
254 |
-
"""
|
255 |
-
final_report = model.generate_content([
|
256 |
-
|
257 |
-
sherlock_guidelines,
|
258 |
-
report_prompt,
|
259 |
-
str(web_search_results),
|
260 |
-
str(wikipedia_results)
|
261 |
-
])
|
262 |
st.header("Case Report")
|
263 |
st.write(final_report.text)
|
264 |
|
|
|
110 |
st.error(f"Error processing image: {e}")
|
111 |
return image_insights
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
def search_internet(case_text):
|
114 |
"""Generates search queries using Gemini 1.5 Pro and performs internet searches for case-related information."""
|
115 |
prompt = """
|
|
|
162 |
st.session_state.chat_history = []
|
163 |
|
164 |
def investigate():
|
165 |
+
"""Handles the case investigation process with Pandas for embeddings."""
|
166 |
st.subheader("Case Investigation")
|
167 |
|
168 |
# File upload with clear labels and progress bars
|
|
|
190 |
"keywords": keywords
|
191 |
}
|
192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
prompt = """
|
194 |
You are Sherlock Holmes, the renowned detective. Analyze the following case information and provide insights or
|
195 |
suggestions for further investigation:
|
|
|
201 |
with st.expander("Sherlock's Analysis and Suggestions:"):
|
202 |
st.write(response.text)
|
203 |
|
|
|
204 |
web_search_results = []
|
205 |
|
206 |
search_options = st.multiselect("Search for additional clues:", ["Internet"], default=["Internet"])
|
|
|
213 |
st.write(f"**Snippet:** {result['snippet']}")
|
214 |
st.write(f"**URL:** {result['url']}")
|
215 |
|
216 |
+
# Generate report button
|
217 |
if st.button("Generate Case Report"):
|
218 |
with st.spinner("Generating report..."):
|
219 |
report_prompt = """
|
220 |
You are Sherlock Holmes, the renowned detective. Based on the case information, your analysis, findings from
|
221 |
+
the web, and the extracted keywords, generate a comprehensive case report in your signature style,
|
222 |
including deductions, potential suspects, and conclusions.
|
223 |
+
"""
|
224 |
+
final_report = model.generate_content([sherlock_persona, sherlock_guidelines, report_prompt,
|
225 |
+
str(web_search_results)])
|
|
|
|
|
|
|
|
|
|
|
226 |
st.header("Case Report")
|
227 |
st.write(final_report.text)
|
228 |
|