Afeezee commited on
Commit
81e4a59
·
verified ·
1 Parent(s): 1778d1c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +93 -0
app.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from cerebras.cloud.sdk import Cerebras
3
+ import gradio as gr
4
+ import folium
5
+ from geopy.geocoders import Nominatim
6
+ from IPython.display import HTML
7
+ import plotly.express as px
8
+
9
+ # Initialize Cerebras client
10
+ client = Cerebras(api_key="csk-vy9xw6mmk38ytjwyn34cty6e99f5j3c3m28xdphrv6nxj363")
11
+
12
+ def generate_country_info(country_name):
13
+ messages = [
14
+ {
15
+ "role": "system",
16
+ "content": "You have wide and specialised knowledge about each country of the world. Write comprehensive general information about any country entered in the prompt. like details of independence if any, population, most popular cities, tropical information, cultural information, GDP, the capital and numbers of states or provinces, and tourist attractions"
17
+ },
18
+ {
19
+ "role": "user",
20
+ "content": country_name
21
+ }
22
+ ]
23
+ stream = client.chat.completions.create(
24
+ messages=messages,
25
+ model="llama-3.3-70b",
26
+ stream=True,
27
+ max_completion_tokens=4096,
28
+ temperature=0.54,
29
+ top_p=1
30
+ )
31
+ response = ""
32
+ for chunk in stream:
33
+ response += chunk.choices[0].delta.content or ""
34
+ return response
35
+
36
+ def generate_choropleth_map(country_name):
37
+ data = {
38
+ "Country": [country_name],
39
+ "Values": [100]
40
+ }
41
+ fig = px.choropleth(
42
+ data,
43
+ locations="Country",
44
+ locationmode="country names",
45
+ color="Values",
46
+ color_continuous_scale="Inferno",
47
+ title=f"Country Map Highlighting {country_name}"
48
+ )
49
+ return fig
50
+
51
+ def generate_country_map(country_name):
52
+ geolocator = Nominatim(user_agent="geoapi")
53
+ location = geolocator.geocode(country_name)
54
+ if location:
55
+ latitude, longitude = location.latitude, location.longitude
56
+ country_map = folium.Map(location=[latitude, longitude], zoom_start=6)
57
+ marker = folium.Marker([latitude, longitude], popup=country_name)
58
+ marker.add_to(country_map)
59
+ return country_map._repr_html_()
60
+ else:
61
+ return "Location not found. Please try again."
62
+
63
+ def explore_country(country_name):
64
+ country_info = generate_country_info(country_name)
65
+ choropleth_map = generate_choropleth_map(country_name)
66
+ country_map = generate_country_map(country_name)
67
+ return choropleth_map, country_map, country_info
68
+
69
+ with gr.Blocks() as app:
70
+ gr.Markdown("# Countries Xplorer\nExplore detailed information about any country of the world.\nEnter the name of a country to view its location on maps and learn more about it.")
71
+
72
+ with gr.Row():
73
+ country_input = gr.Textbox(label="Enter the Country You Want to Explore", placeholder="E.g., Nigeria")
74
+
75
+ with gr.Row():
76
+ with gr.Column():
77
+ choropleth_plot = gr.Plot(label="Choropleth Map")
78
+ country_map_html = gr.HTML(label="Country Map")
79
+ with gr.Column():
80
+ country_info_box = gr.Markdown(label="Country Information")
81
+
82
+ def app_interface(country_name):
83
+ choropleth_map, country_map, country_info = explore_country(country_name)
84
+ return (choropleth_map, country_map, country_info)
85
+
86
+ submit_button = gr.Button("Explore")
87
+ submit_button.click(
88
+ app_interface,
89
+ inputs=country_input,
90
+ outputs=[choropleth_plot, country_map_html, country_info_box]
91
+ )
92
+
93
+ app.launch()