Abrar20 commited on
Commit
bc7e478
1 Parent(s): caaae43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -9
app.py CHANGED
@@ -10,13 +10,13 @@ from langchain.prompts import PromptTemplate
10
  def get_chain(llm, retriever):
11
  prompt_template = """
12
  Instructions:
13
- You are a knowledgeable assistant focused on providing safety guidelines for coastal areas during cyclones. Your goal is to generate personalized, clear, and actionable advice based on the specific details provided about the user's infrastructure, proximity to the cyclone pathway, cyclone speed and proximity to the nearest shelter, person's location.
14
 
15
  Please:
16
  - Carefully analyze the provided context from the PDF.
17
  - Offer tailored guidance that addresses the user's unique situation.
18
- - calculating nearest shelter by location of the person(lat,lon) and shelter coordinates(lat,lon)
19
- - calculating Proximity to cyclone by location of the person(lat,lon) and Predicted Cyclone Coordinates(lat,lon).
20
  - Ensure that your advice is practical and directly applicable.
21
  - If information is missing or unclear, use logical assumptions based on the context to provide the best possible recommendations.
22
  - Be concise but thorough, offering detailed steps when necessary to enhance safety and preparedness.
@@ -47,14 +47,14 @@ def load_pdf_to_langchain(pdf_path, repo_id):
47
  retriever = db.as_retriever()
48
  llm = HuggingFaceHub(
49
  repo_id=repo_id,
50
- model_kwargs={'temperature': 0.3, 'max_new_tokens': 2096}
51
  )
52
  qa_chain = get_chain(llm, retriever)
53
  return qa_chain
54
 
55
  def generate_guideline(infrastructure, location, cyclone_predicted_coordinates, cyclone_speed):
56
  if infrastructure and location and cyclone_predicted_coordinates and cyclone_speed:
57
- user_question = f"""{infrastructure} Infrastructure, location of the person(lat,lon) is {location}, Cyclone Speed in knot is {cyclone_speed}, Predicted Cyclone Coordinates(lat,lon) is {cyclone_predicted_coordinates}. Please give guideline what will be best in this context. Give precise instruction by calculating proximity to cyclone by location of the person(lat,lon) and Predicted Cyclone Coordinates(lat,lon). Also give the location of the nearest shelter by calculating location of the person(lat,lon) and shelter coordinates(lat,lon) (from the text chunk given). Don't give Proximity to cyclone and Proximity to shelter though (only use this to generate the guideline). Also give the helpline number in last: 333."""
58
  result = qa({'query': user_question})
59
  return result['result']
60
  else:
@@ -80,9 +80,22 @@ with gr.Blocks(css=css, theme='Taithrah/Minimal') as demo:
80
  'HuggingFaceH4/zephyr-7b-beta',
81
  'meta-llama/Llama-2-7b-chat-hf',
82
  '01-ai/Yi-6B-200K',
83
- 'cognitivecomputations/dolphin-2.5-mixtral-8x7b'
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  ],
85
- value='mistralai/Mistral-7B-Instruct-v0.1'
86
  )
87
 
88
  # Status display
@@ -92,8 +105,8 @@ with gr.Blocks(css=css, theme='Taithrah/Minimal') as demo:
92
 
93
  # Input fields for user information
94
  infrastructure = gr.Textbox(label='Infrastructure')
95
- location = gr.Textbox(label='Location Coordinates (lat,lon)')
96
- cyclone_predicted_coordinates = gr.Textbox(label='Predicted Cyclone Coordinates (lat,lon)')
97
  cyclone_speed = gr.Textbox(label='Cyclone Speed in Knots')
98
 
99
  submit_btn = gr.Button('Generate Guideline')
 
10
  def get_chain(llm, retriever):
11
  prompt_template = """
12
  Instructions:
13
+ You are a knowledgeable assistant focused on providing safety guidelines for coastal areas during cyclones. Your goal is to generate personalized, clear, and actionable advice based on the specific details provided about the user's infrastructure, proximity to the cyclone pathway, cyclone speed, and proximity to the nearest shelter, person's location.
14
 
15
  Please:
16
  - Carefully analyze the provided context from the PDF.
17
  - Offer tailored guidance that addresses the user's unique situation.
18
+ - Calculate the nearest shelter by location of the person (lat, lon) and shelter coordinates (lat, lon).
19
+ - Calculate proximity to cyclone by location of the person (lat, lon) and predicted cyclone coordinates (lat, lon).
20
  - Ensure that your advice is practical and directly applicable.
21
  - If information is missing or unclear, use logical assumptions based on the context to provide the best possible recommendations.
22
  - Be concise but thorough, offering detailed steps when necessary to enhance safety and preparedness.
 
47
  retriever = db.as_retriever()
48
  llm = HuggingFaceHub(
49
  repo_id=repo_id,
50
+ model_kwargs={'temperature': 0.5, 'max_new_tokens': 2096}
51
  )
52
  qa_chain = get_chain(llm, retriever)
53
  return qa_chain
54
 
55
  def generate_guideline(infrastructure, location, cyclone_predicted_coordinates, cyclone_speed):
56
  if infrastructure and location and cyclone_predicted_coordinates and cyclone_speed:
57
+ user_question = f"""{infrastructure} Infrastructure, location of the person (lat, lon) is {location}, Cyclone Speed in knots is {cyclone_speed}, Predicted Cyclone Coordinates (lat, lon) is {cyclone_predicted_coordinates}. Please give guidelines on what will be best in this context. Give precise instructions by calculating proximity to cyclone by location of the person (lat, lon) and predicted cyclone coordinates (lat, lon). Also, give the location of the nearest shelter by calculating location of the person (lat, lon) and shelter coordinates (lat, lon) (from the text chunk given). Don't give proximity to cyclone and proximity to shelter though (only use this to generate the guideline). Also, give the helpline number at the end: 333."""
58
  result = qa({'query': user_question})
59
  return result['result']
60
  else:
 
80
  'HuggingFaceH4/zephyr-7b-beta',
81
  'meta-llama/Llama-2-7b-chat-hf',
82
  '01-ai/Yi-6B-200K',
83
+ 'cognitivecomputations/dolphin-2.5-mixtral-8x7b',
84
+ 'tiiuae/falcon-7b-instruct',
85
+ 'tiiuae/falcon-7b',
86
+ 'google/flan-t5-base',
87
+ 'google/flan-t5-large',
88
+ 'google/flan-t5-xl',
89
+ 'bigscience/bloom-7b1',
90
+ 'EleutherAI/gpt-neo-2.7B',
91
+ 'EleutherAI/gpt-j-6B',
92
+ 'facebook/opt-6.7b',
93
+ 'facebook/galactica-6.7b',
94
+ 'cerebras/Cerebras-GPT-6.7B',
95
+ 'RWKV/rwkv-4-7b-pile',
96
+ # Add more models here as desired
97
  ],
98
+ value='mistralai/Mistral-7B-Instruct-v0.1"
99
  )
100
 
101
  # Status display
 
105
 
106
  # Input fields for user information
107
  infrastructure = gr.Textbox(label='Infrastructure')
108
+ location = gr.Textbox(label='Location Coordinates (lat, lon)')
109
+ cyclone_predicted_coordinates = gr.Textbox(label='Predicted Cyclone Coordinates (lat, lon)')
110
  cyclone_speed = gr.Textbox(label='Cyclone Speed in Knots')
111
 
112
  submit_btn = gr.Button('Generate Guideline')