Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,27 +30,29 @@ def generate_signature():
|
|
| 30 |
def get_coordinates(location_name):
|
| 31 |
prompt_template = PromptTemplate(
|
| 32 |
input_variables=["location"],
|
| 33 |
-
template="What are the exact latitude and longitude of {location}? Please provide
|
| 34 |
)
|
| 35 |
|
| 36 |
llm = ChatOpenAI(model="gpt-4", openai_api_key=openai.api_key)
|
| 37 |
chain = LLMChain(llm=llm, prompt=prompt_template)
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
| 54 |
|
| 55 |
# Function to make the POST request to the Hotelbeds API and handle pagination
|
| 56 |
def fetch_activities(latitude, longitude, from_date, to_date, language="en", paxes=[{"age": 5}, {"age": 70}], order="DEFAULT"):
|
|
|
|
| 30 |
def get_coordinates(location_name):
|
| 31 |
prompt_template = PromptTemplate(
|
| 32 |
input_variables=["location"],
|
| 33 |
+
template="What are the exact latitude and longitude of {location}? Please provide the values in decimal degrees."
|
| 34 |
)
|
| 35 |
|
| 36 |
llm = ChatOpenAI(model="gpt-4", openai_api_key=openai.api_key)
|
| 37 |
chain = LLMChain(llm=llm, prompt=prompt_template)
|
| 38 |
|
| 39 |
+
result = chain.run(location=location_name).strip()
|
| 40 |
+
# This line is new: processing the response to handle directional letters
|
| 41 |
+
try:
|
| 42 |
+
# Clean the result to remove degrees symbol and directional letters, then split by comma
|
| 43 |
+
cleaned_result = result.replace('°', '').replace(' N', '').replace(' S', '').replace(' E', '').replace(' W', '')
|
| 44 |
+
coordinates = cleaned_result.split(',')
|
| 45 |
+
# Convert to float, and handle negative values for southern and western hemispheres
|
| 46 |
+
latitude = float(coordinates[0].strip())
|
| 47 |
+
longitude = float(coordinates[1].strip())
|
| 48 |
+
if 'S' in result.split(',')[0]:
|
| 49 |
+
latitude = -latitude
|
| 50 |
+
if 'W' in result.split(',')[1]:
|
| 51 |
+
longitude = -longitude
|
| 52 |
+
return latitude, longitude
|
| 53 |
+
except ValueError as e:
|
| 54 |
+
st.error(f"Unable to parse coordinates from the AI's response: '{result}'. Error: {str(e)}")
|
| 55 |
+
return None, None
|
| 56 |
|
| 57 |
# Function to make the POST request to the Hotelbeds API and handle pagination
|
| 58 |
def fetch_activities(latitude, longitude, from_date, to_date, language="en", paxes=[{"age": 5}, {"age": 70}], order="DEFAULT"):
|