Hk4crprasad commited on
Commit
f0d439c
·
verified ·
1 Parent(s): 528a661

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -54
app.py CHANGED
@@ -577,31 +577,19 @@ st.set_page_config(
577
  )
578
  # Path: Main.py
579
  #Author: Sergio Demis Lopez Martinez
580
-
581
  temperature = 0.9
582
  top_p = 1.0
583
  top_k = 1
584
  max_output_tokens = 1024
585
  threshold_options = ["BLOCK_NONE", "BLOCK_ONLY_HIGH", "BLOCK_MEDIUM_AND_ABOVE", "BLOCK_LOW_AND_ABOVE"]
586
-
587
- cols=st.columns(5)
588
-
589
- with cols[0]:
590
- image_atachment = st.toggle("Attach image", value=False, help="Activate this mode to attach an image and let the chatbot read it")
591
-
592
- with cols[1]:
593
- txt_atachment = st.toggle("Attach text file", value=False, help="Activate this mode to attach a text file and let the chatbot read it")
594
-
595
- with cols[2]:
596
- csv_excel_atachment = st.toggle("Attach CSV or Excel", value=False, help="Activate this mode to attach a CSV or Excel file and let the chatbot read it")
597
-
598
- with cols[3]:
599
- graphviz_mode = st.toggle("Graphviz mode", value=False, help="Activate this mode to generate a graph with graphviz in .dot from your message")
600
-
601
- with cols[4]:
602
- pdf_mode = st.toggle("Pdf ask mode", value=False, help="Activate this mode to generate a graph with graphviz in .dot from your message")
603
- #------------------------------------------------------------
604
-
605
  if pdf_mode:
606
  with st.sidebar:
607
  st.title("Menu:")
@@ -612,47 +600,31 @@ if pdf_mode:
612
  text_chunks = get_text_chunks(raw_text)
613
  get_vector_store(text_chunks)
614
  st.success("Done")
615
-
616
  generation_config = {
617
  "temperature": temperature,
618
  "top_p": top_p,
619
  "top_k": top_k,
620
  "max_output_tokens": max_output_tokens,
621
  }
622
- SAFETY_SETTINGS = [
623
- {"category": "HARM_CATEGORY_HARASSMENT", "threshold": 0}, # Default to BLOCK_NONE
624
- {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": 0},
625
- {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": 0},
626
- {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": 0},
627
- ]
628
  else:
629
- SAFETY_SETTINGS = [
630
- {"category": "HARM_CATEGORY_HARASSMENT", "threshold": 0}, # Default to BLOCK_NONE
631
- {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": 0},
632
- {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": 0},
633
- {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": 0},
634
- ]
635
- generation_config = {
636
- "temperature": temperature,
637
- "top_p": top_p,
638
- "top_k": top_k,
639
- "max_output_tokens": max_output_tokens,
640
- }
641
  with st.sidebar:
642
  st.subheader("Settings")
643
  temperature1 = st.slider("Temperature", 0.1, 1.0, temperature)
644
- top_p1 = st.slider("Top P", 0.1, 1.0, top_p, 0.01) # Use float step
645
  top_k1 = st.slider("Top K", 1, 30, top_k)
646
  max_output_tokens1 = st.slider("Max Output Tokens", 100, 2048, max_output_tokens)
647
-
648
  st.subheader("Safety Settings")
 
649
  for setting in SAFETY_SETTINGS:
650
  category = setting["category"]
651
  index = st.selectbox(f"{category} Threshold", range(len(threshold_options)))
652
 
653
  # Update safety settings based on user input
654
- setting["threshold"] = threshold_options[index]
655
-
656
  # Update generation_config based on user input
657
  temperature = temperature1
658
  top_p = top_p1
@@ -664,20 +636,12 @@ else:
664
  "top_k": top_k,
665
  "max_output_tokens": max_output_tokens,
666
  }
667
-
668
  st.sidebar.subheader("Selected Values")
669
  st.sidebar.write(f"Temperature: {temperature}")
670
  st.sidebar.write(f"Top P: {top_p}")
671
  st.sidebar.write(f"Top K: {top_k}")
672
  st.sidebar.write(f"Max Output Tokens: {max_output_tokens}")
673
-
674
- SAFETY_SETTINGS = [
675
- {"category": "HARM_CATEGORY_HARASSMENT", "threshold": threshold_options[index]}, # Default to BLOCK_NONE
676
- {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": threshold_options[index]},
677
- {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": threshold_options[index]},
678
- {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": threshold_options[index]},
679
- ]
680
-
681
 
682
  #HEADER
683
  st.markdown('''
@@ -735,7 +699,7 @@ def load_model() -> genai.GenerativeModel:
735
  'gemini-pro'.
736
  :return: an instance of the `genai.GenerativeModel` class.
737
  """
738
- model = genai.GenerativeModel('gemini-pro', safety_settings=SAFETY_SETTINGS, generation_config=generation_config)
739
  return model
740
 
741
  @st.cache_resource
@@ -815,6 +779,24 @@ if len(st.session_state.chat_session) > 0:
815
 
816
  #st.session_state.chat.history
817
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
818
  if image_atachment:
819
  image = st.file_uploader("Upload your image", type=['png', 'jpg', 'jpeg'])
820
  url = st.text_input("Or paste your image url")
@@ -891,7 +873,7 @@ if prompt:
891
 
892
  with st.spinner(spinertxt):
893
  if len(prmt['parts']) > 1:
894
- response = vision.generate_content(prmt['parts'],stream=True,safety_settings=SAFETY_SETTINGS, generation_config=generation_config)
895
  response.resolve()
896
  else:
897
  response = None
 
577
  )
578
  # Path: Main.py
579
  #Author: Sergio Demis Lopez Martinez
 
580
  temperature = 0.9
581
  top_p = 1.0
582
  top_k = 1
583
  max_output_tokens = 1024
584
  threshold_options = ["BLOCK_NONE", "BLOCK_ONLY_HIGH", "BLOCK_MEDIUM_AND_ABOVE", "BLOCK_LOW_AND_ABOVE"]
585
+ SAFETY_SETTINGS = [
586
+ {"category": "HARM_CATEGORY_HARASSMENT", "threshold": 0},
587
+ {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": 0},
588
+ {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": 0},
589
+ {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": 0},
590
+ ]
591
+ pdf_mode = False
592
+ # ------------------------------------------------------------
 
 
 
 
 
 
 
 
 
 
 
593
  if pdf_mode:
594
  with st.sidebar:
595
  st.title("Menu:")
 
600
  text_chunks = get_text_chunks(raw_text)
601
  get_vector_store(text_chunks)
602
  st.success("Done")
603
+
604
  generation_config = {
605
  "temperature": temperature,
606
  "top_p": top_p,
607
  "top_k": top_k,
608
  "max_output_tokens": max_output_tokens,
609
  }
610
+ safety_settings = SAFETY_SETTINGS
 
 
 
 
 
611
  else:
 
 
 
 
 
 
 
 
 
 
 
 
612
  with st.sidebar:
613
  st.subheader("Settings")
614
  temperature1 = st.slider("Temperature", 0.1, 1.0, temperature)
615
+ top_p1 = st.slider("Top P", 0.1, 1.0, top_p, 0.01)
616
  top_k1 = st.slider("Top K", 1, 30, top_k)
617
  max_output_tokens1 = st.slider("Max Output Tokens", 100, 2048, max_output_tokens)
618
+
619
  st.subheader("Safety Settings")
620
+ safety_settings = []
621
  for setting in SAFETY_SETTINGS:
622
  category = setting["category"]
623
  index = st.selectbox(f"{category} Threshold", range(len(threshold_options)))
624
 
625
  # Update safety settings based on user input
626
+ safety_settings.append({"category": category, "threshold": threshold_options[index]})
627
+
628
  # Update generation_config based on user input
629
  temperature = temperature1
630
  top_p = top_p1
 
636
  "top_k": top_k,
637
  "max_output_tokens": max_output_tokens,
638
  }
639
+
640
  st.sidebar.subheader("Selected Values")
641
  st.sidebar.write(f"Temperature: {temperature}")
642
  st.sidebar.write(f"Top P: {top_p}")
643
  st.sidebar.write(f"Top K: {top_k}")
644
  st.sidebar.write(f"Max Output Tokens: {max_output_tokens}")
 
 
 
 
 
 
 
 
645
 
646
  #HEADER
647
  st.markdown('''
 
699
  'gemini-pro'.
700
  :return: an instance of the `genai.GenerativeModel` class.
701
  """
702
+ model = genai.GenerativeModel('gemini-pro', safety_settings=safety_settings, generation_config=generation_config)
703
  return model
704
 
705
  @st.cache_resource
 
779
 
780
  #st.session_state.chat.history
781
 
782
+
783
+ cols = st.columns(5)
784
+
785
+ with cols[0]:
786
+ image_attachment = st.toggle("Attach image", value=False, help="Activate this mode to attach an image and let the chatbot read it")
787
+
788
+ with cols[1]:
789
+ txt_attachment = st.toggle("Attach text file", value=False, help="Activate this mode to attach a text file and let the chatbot read it")
790
+
791
+ with cols[2]:
792
+ csv_excel_attachment = st.toggle("Attach CSV or Excel", value=False, help="Activate this mode to attach a CSV or Excel file and let the chatbot read it")
793
+
794
+ with cols[3]:
795
+ graphviz_mode = st.toggle("Graphviz mode", value=False, help="Activate this mode to generate a graph with graphviz in .dot from your message")
796
+
797
+ with cols[4]:
798
+ pdf_mode = st.toggle("Pdf ask mode", value=False, help="Activate this mode to generate a graph with graphviz in .dot from your message")
799
+
800
  if image_atachment:
801
  image = st.file_uploader("Upload your image", type=['png', 'jpg', 'jpeg'])
802
  url = st.text_input("Or paste your image url")
 
873
 
874
  with st.spinner(spinertxt):
875
  if len(prmt['parts']) > 1:
876
+ response = vision.generate_content(prmt['parts'],stream=True,safety_settings=safety_settings, generation_config=generation_config)
877
  response.resolve()
878
  else:
879
  response = None