Hk4crprasad commited on
Commit
d45a584
·
verified ·
1 Parent(s): 7233920

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -58
app.py CHANGED
@@ -588,62 +588,7 @@ SAFETY_SETTINGS = [
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:")
596
- pdf_docs = st.file_uploader("Upload your PDF Files and Click on the Submit & Process Button", accept_multiple_files=True)
597
- if st.button("Submit & Process"):
598
- with st.spinner("Processing..."):
599
- raw_text = get_pdf_text(pdf_docs)
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
631
- top_k = top_k1
632
- max_output_tokens = max_output_tokens1
633
- generation_config = {
634
- "temperature": temperature,
635
- "top_p": top_p,
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('''
648
  Powered by Hk4crprasad <img src="https://i.ibb.co/BVJ2tCG/OIG-47-modified.png" width="20" height="20">
649
  , Streamlit and Python''', unsafe_allow_html=True)
@@ -699,7 +644,7 @@ def load_model() -> genai.GenerativeModel:
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
@@ -805,7 +750,45 @@ else:
805
  url = ''
806
 
807
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
808
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
809
  if txt_atachment:
810
  txtattachment = st.file_uploader("Upload your text file", type=['txt, py, go, java, php, etc'])
811
  else:
@@ -873,7 +856,17 @@ if prompt:
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
@@ -926,7 +919,17 @@ if prompt:
926
  else:
927
  piro = f"{prmt['parts'][0]}"
928
 
929
- st.session_state.chat.send_message(f"{piro}", stream=True)
 
 
 
 
 
 
 
 
 
 
930
  response = st.session_state.chat.last
931
  response.resolve()
932
  except StopCandidateException as sce:
 
588
  {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": 0},
589
  {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": 0},
590
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
591
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
592
  st.markdown('''
593
  Powered by Hk4crprasad <img src="https://i.ibb.co/BVJ2tCG/OIG-47-modified.png" width="20" height="20">
594
  , Streamlit and Python''', unsafe_allow_html=True)
 
644
  'gemini-pro'.
645
  :return: an instance of the `genai.GenerativeModel` class.
646
  """
647
+ model = genai.GenerativeModel('gemini-pro')
648
  return model
649
 
650
  @st.cache_resource
 
750
  url = ''
751
 
752
 
753
+ if pdf_mode:
754
+ with st.sidebar:
755
+ st.title("Menu:")
756
+ pdf_docs = st.file_uploader("Upload your PDF Files and Click on the Submit & Process Button", accept_multiple_files=True)
757
+ if st.button("Submit & Process"):
758
+ with st.spinner("Processing..."):
759
+ raw_text = get_pdf_text(pdf_docs)
760
+ text_chunks = get_text_chunks(raw_text)
761
+ get_vector_store(text_chunks)
762
+ st.success("Done")
763
+ else:
764
+ with st.sidebar:
765
+ st.subheader("Settings")
766
+ temperature1 = st.slider("Temperature", 0.1, 1.0, temperature)
767
+ top_p1 = st.slider("Top P", 0.1, 1.0, top_p, 0.01)
768
+ top_k1 = st.slider("Top K", 1, 30, top_k)
769
+ max_output_tokens1 = st.slider("Max Output Tokens", 100, 2048, max_output_tokens)
770
 
771
+ st.subheader("Safety Settings")
772
+ safety_settings = []
773
+ for setting in SAFETY_SETTINGS:
774
+ category = setting["category"]
775
+ index = st.selectbox(f"{category} Threshold", range(len(threshold_options)))
776
+
777
+ # Update safety settings based on user input
778
+ safety_settings.append({"category": category, "threshold": threshold_options[index]})
779
+
780
+ # Update generation_config based on user input
781
+ temperature = temperature1
782
+ top_p = top_p1
783
+ top_k = top_k1
784
+ max_output_tokens = max_output_tokens1
785
+ st.sidebar.subheader("Selected Values")
786
+ st.sidebar.write(f"Temperature: {temperature}")
787
+ st.sidebar.write(f"Top P: {top_p}")
788
+ st.sidebar.write(f"Top K: {top_k}")
789
+ st.sidebar.write(f"Max Output Tokens: {max_output_tokens}")
790
+
791
+ #HEADER
792
  if txt_atachment:
793
  txtattachment = st.file_uploader("Upload your text file", type=['txt, py, go, java, php, etc'])
794
  else:
 
856
 
857
  with st.spinner(spinertxt):
858
  if len(prmt['parts']) > 1:
859
+ response = vision.generate_content(prmt['parts'],stream=True,safety_settings=[
860
+ {"category": "HARM_CATEGORY_HARASSMENT", "threshold": threshold_options[index] for index in range(len(threshold_options))},
861
+ {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": threshold_options[index] for index in range(len(threshold_options))},
862
+ {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": threshold_options[index] for index in range(len(threshold_options))},
863
+ {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": threshold_options[index] for index in range(len(threshold_options))},
864
+ ], generation_config = {
865
+ "temperature": temperature,
866
+ "top_p": top_p,
867
+ "top_k": top_k,
868
+ "max_output_tokens": max_output_tokens,
869
+ })
870
  response.resolve()
871
  else:
872
  response = None
 
919
  else:
920
  piro = f"{prmt['parts'][0]}"
921
 
922
+ st.session_state.chat.send_message(f"{piro}",generation_config = {
923
+ "temperature": temperature,
924
+ "top_p": top_p,
925
+ "top_k": top_k,
926
+ "max_output_tokens": max_output_tokens,
927
+ },safety_settings=[
928
+ {"category": "HARM_CATEGORY_HARASSMENT", "threshold": threshold_options[index] for index in range(len(threshold_options))},
929
+ {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": threshold_options[index] for index in range(len(threshold_options))},
930
+ {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": threshold_options[index] for index in range(len(threshold_options))},
931
+ {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": threshold_options[index] for index in range(len(threshold_options))},
932
+ ], stream=True)
933
  response = st.session_state.chat.last
934
  response.resolve()
935
  except StopCandidateException as sce: