Hk4crprasad commited on
Commit
fa0fd59
·
verified ·
1 Parent(s): e199a23

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -19
app.py CHANGED
@@ -25,6 +25,8 @@ load_dotenv()
25
  import datetime
26
  import fitz # PyMuPDF
27
 
 
 
28
  history=[
29
  {
30
  "parts": [
@@ -519,7 +521,6 @@ def user_input(user_question):
519
 
520
  url = "https://y39t47-8080.csb.app/search"
521
 
522
- weathe_key = os.getenv("WEATHER_KEY")
523
  def print_weather_data(api_key, location):
524
  base_url = "http://api.weatherstack.com/forecast"
525
  params = {"access_key": api_key, "query": location}
@@ -576,25 +577,45 @@ st.set_page_config(
576
  )
577
  # Path: Main.py
578
  #Author: Sergio Demis Lopez Martinez
 
 
 
 
 
 
579
  #------------------------------------------------------------
580
  SAFETY_SETTINGS = [
581
- {
582
- "category": "HARM_CATEGORY_HARASSMENT",
583
- "threshold": "BLOCK_NONE"
584
- },
585
- {
586
- "category": "HARM_CATEGORY_HATE_SPEECH",
587
- "threshold": "BLOCK_NONE"
588
- },
589
- {
590
- "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
591
- "threshold": "BLOCK_NONE"
592
- },
593
- {
594
- "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
595
- "threshold": "BLOCK_NONE"
596
- }
597
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
598
  #HEADER
599
  st.markdown('''
600
  Powered by Hk4crprasad <img src="https://i.ibb.co/BVJ2tCG/OIG-47-modified.png" width="20" height="20">
@@ -651,7 +672,7 @@ def load_model() -> genai.GenerativeModel:
651
  'gemini-pro'.
652
  :return: an instance of the `genai.GenerativeModel` class.
653
  """
654
- model = genai.GenerativeModel('gemini-pro', safety_settings=SAFETY_SETTINGS)
655
  return model
656
 
657
  @st.cache_resource
@@ -836,7 +857,7 @@ if prompt:
836
 
837
  with st.spinner(spinertxt):
838
  if len(prmt['parts']) > 1:
839
- response = vision.generate_content(prmt['parts'],stream=True,safety_settings=SAFETY_SETTINGS)
840
  response.resolve()
841
  else:
842
  response = None
 
25
  import datetime
26
  import fitz # PyMuPDF
27
 
28
+ weathe_key = os.getenv("WEATHER_KEY")
29
+
30
  history=[
31
  {
32
  "parts": [
 
521
 
522
  url = "https://y39t47-8080.csb.app/search"
523
 
 
524
  def print_weather_data(api_key, location):
525
  base_url = "http://api.weatherstack.com/forecast"
526
  params = {"access_key": api_key, "query": location}
 
577
  )
578
  # Path: Main.py
579
  #Author: Sergio Demis Lopez Martinez
580
+ generation_config = {
581
+ "temperature": 0.9,
582
+ "top_p": 1,
583
+ "top_k": 1,
584
+ "max_output_tokens": 2048,
585
+ }
586
  #------------------------------------------------------------
587
  SAFETY_SETTINGS = [
588
+ {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"},
589
+ {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"},
590
+ {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"},
591
+ {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"},
 
 
 
 
 
 
 
 
 
 
 
 
592
  ]
593
+
594
+ with st.sidebar:
595
+ st.subheader("Settings")
596
+ temperature = st.slider("Temperature", 0.1, 1.0, generation_config["temperature"])
597
+ top_p = st.slider("Top P", 0.1, 1.0, generation_config["top_p"])
598
+ top_k = st.slider("Top K", 1, 100, generation_config["top_k"])
599
+ max_output_tokens = st.slider("Max Output Tokens", 100, 5000, generation_config["max_output_tokens"])
600
+ apply_button = st.button("Apply")
601
+
602
+ # Check if the "Apply" button is clicked
603
+ if apply_button:
604
+ # Update generation_config based on user input
605
+ generation_config["temperature"] = temperature
606
+ generation_config["top_p"] = top_p
607
+ generation_config["top_k"] = top_k
608
+ generation_config["max_output_tokens"] = max_output_tokens
609
+
610
+ with st.sidebar:
611
+ st.subheader("Safety Settings")
612
+ for setting in SAFETY_SETTINGS:
613
+ category = setting["category"]
614
+ threshold = st.selectbox(f"{category} Threshold", ["BLOCK_NONE", "BLOCK_LOW_AND_ABOVE", "BLOCK_MID_AND_ABOVE", "BLOCK_HIGH"], index=0)
615
+
616
+ # Update safety settings based on user input
617
+ setting["threshold"] = threshold
618
+
619
  #HEADER
620
  st.markdown('''
621
  Powered by Hk4crprasad <img src="https://i.ibb.co/BVJ2tCG/OIG-47-modified.png" width="20" height="20">
 
672
  'gemini-pro'.
673
  :return: an instance of the `genai.GenerativeModel` class.
674
  """
675
+ model = genai.GenerativeModel('gemini-pro', safety_settings=SAFETY_SETTINGS, generation_config=generation_config)
676
  return model
677
 
678
  @st.cache_resource
 
857
 
858
  with st.spinner(spinertxt):
859
  if len(prmt['parts']) > 1:
860
+ response = vision.generate_content(prmt['parts'],stream=True,safety_settings=SAFETY_SETTINGS, generation_config=generation_config)
861
  response.resolve()
862
  else:
863
  response = None