jayash391 commited on
Commit
7c7fcaf
·
verified ·
1 Parent(s): ba46372

Update sherlock2.py

Browse files
Files changed (1) hide show
  1. sherlock2.py +24 -40
sherlock2.py CHANGED
@@ -15,6 +15,9 @@ import textract
15
 
16
  load_dotenv()
17
 
 
 
 
18
  # Load pre-trained Gemini model
19
  model = genai.GenerativeModel('models/gemini-1.0-pro')
20
  vision_model = genai.GenerativeModel('models/gemini-pro-vision')
@@ -230,22 +233,18 @@ def display_chat_history():
230
  def clear_chat():
231
  st.session_state.chat_history = []
232
 
233
- def show_welcome_popup():
234
- """Displays a popup with information about Sherlock and instructions."""
235
- st.info("""
236
- **Welcome to AI Detective Sherlock Holmes!**
237
-
238
- **About Sherlock:**
239
- Sherlock Holmes is a brilliant detective known for his exceptional deductive reasoning skills. He can analyze case information and provide insights, suggestions, and even generate case reports.
240
 
241
- **How to Chat with Sherlock:**
242
- 1. Go to the "Chat with Sherlock" page.
243
- 2. Type your questions or statements in the input box.
244
- 3. Click "Enter" or the "Send" button to get Sherlock's response.
245
- 4. Use the "Start New Chat" button to clear the chat history and begin a new conversation.
246
 
247
- **Enjoy your consultation with the legendary detective!**
248
- """)
249
 
250
  def investigate():
251
  """Handles the case investigation process with improved UI and functionality."""
@@ -385,32 +384,17 @@ def main():
385
  st.title("AI Detective Sherlock Holmes")
386
  st.header("_'Elementary, my dear Watson!'_")
387
 
388
- # Get Gemini API key from user
389
- api_key = st.sidebar.text_input("Enter your Gemini API Key:", type="password", key="api_key")
390
- if api_key:
391
- os.environ["GEMINI_API_KEY_PROJECTID"] = api_key
392
- try:
393
- # Attempt to configure Gemini API access
394
- genai.configure(api_key=api_key)
395
- # Load pre-trained Gemini model (to test API key validity)
396
- model = genai.GenerativeModel('models/gemini-1.0-pro')
397
-
398
- pages = {
399
- "Investigate a Case": investigate,
400
- "Chat with Sherlock": chat_with_sherlock
401
- }
402
-
403
- st.sidebar.title("Navigation")
404
- page = st.sidebar.radio("Choose an action:", list(pages.keys()))
405
-
406
- # Show intro popup only after successful API key validation
407
- show_sherlock_intro()
408
-
409
- pages[page]()
410
- except Exception as e:
411
- st.error("Invalid Gemini API Key. Please try again.")
412
- else:
413
- st.warning("Please enter your Gemini API Key to proceed.")
414
 
415
  if __name__ == "__main__":
416
  main()
 
15
 
16
  load_dotenv()
17
 
18
+ # Configure Gemini API access
19
+ genai.configure(api_key=os.getenv("GEMINI_API_KEY_PROJECTID"))
20
+
21
  # Load pre-trained Gemini model
22
  model = genai.GenerativeModel('models/gemini-1.0-pro')
23
  vision_model = genai.GenerativeModel('models/gemini-pro-vision')
 
233
  def clear_chat():
234
  st.session_state.chat_history = []
235
 
236
+ def show_intro_popup():
237
+ """Displays a popup with information about Sherlock and chat instructions."""
238
+ with st.expander("Welcome to AI Detective Sherlock Holmes!"): # Use expander for a collapsible popup
239
+ st.write("""
240
+ **Meet Sherlock Holmes, the world's most renowned detective!**
 
 
241
 
242
+ This application allows you to:
243
+ * **Investigate Cases:** Upload case files and images for Sherlock to analyze.
244
+ * **Chat with Sherlock:** Ask him questions and get his insights.
 
 
245
 
246
+ **To chat with Sherlock, go to the "Chat with Sherlock" page in the sidebar.**
247
+ """)
248
 
249
  def investigate():
250
  """Handles the case investigation process with improved UI and functionality."""
 
384
  st.title("AI Detective Sherlock Holmes")
385
  st.header("_'Elementary, my dear Watson!'_")
386
 
387
+
388
+ pages = {
389
+ "Investigate a Case": investigate,
390
+ "Chat with Sherlock": chat_with_sherlock
391
+ }
392
+
393
+ show_intro_popup()
394
+
395
+ st.sidebar.title("Navigation")
396
+ page = st.sidebar.radio("Choose an action:", list(pages.keys()))
397
+ pages[page]()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
398
 
399
  if __name__ == "__main__":
400
  main()