disham993 commited on
Commit
33fbb25
β€’
1 Parent(s): 37ee7bf

Application file added.

Browse files
Files changed (9) hide show
  1. .gitignore +3 -0
  2. README.md +21 -12
  3. app.py +13 -0
  4. data/WHR2023.csv +138 -0
  5. gradio_app.py +33 -0
  6. requirements.txt +104 -0
  7. utils/__init__.py +2 -0
  8. utils/constants.py +9 -0
  9. utils/helper.py +46 -0
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ **/*__pycache__
2
+ **/*.chroma
3
+ flagged
README.md CHANGED
@@ -1,12 +1,21 @@
1
- ---
2
- title: World Happiness Report 2023 Q And A Bot
3
- emoji: πŸ‘
4
- colorFrom: gray
5
- colorTo: gray
6
- sdk: gradio
7
- sdk_version: 3.24.1
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
1
+ # Question and Answering Gradio Application for World Happiness Report 2023
2
+
3
+ ## Motivation
4
+
5
+ In this project, we will be building simple gradio application that takes in questions related to the World Happiness Report from 2023 and answers them to the user.
6
+
7
+ This project is revolutionary game changer in the world of Data Science specially for the Data Analysts and the stakeholders at managerial levels which will save us a lot of time and boost in productivity.
8
+
9
+
10
+ ## Libraries Used
11
+
12
+ We will be using LangChain, special library that helps in combining the Large Language Models (LLMS) and other sources of data to unleash true potential of LLMs. Basically, it acts as a chain between LLMs and other sources of data. Therefore, helps the developers to create SOTA applications. In this project, LangChain helps in combining LLM (text-embedding-ada-002-v2) used from OpenAI with CSV file to provide Question and Answering Bot.
13
+
14
+ Gradio library is used to provide beautiful user interface for the application.
15
+
16
+ ## Resources
17
+ - LangChain Library: https://github.com/hwchase17/langchain
18
+ - Inspired from: https://twitter.com/pwang_szn/status/1642104548109201410
19
+ - Dataset Resource: https://www.kaggle.com/datasets/ajaypalsinghlo/world-happiness-report-2023
20
+
21
+
app.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, sys
2
+ from os.path import dirname as up
3
+
4
+ sys.path.append(os.path.abspath(os.path.join(up(__file__), os.pardir)))
5
+
6
+ from utils import *
7
+ from gradio_app import *
8
+
9
+ demo = gradio_interface(return_response_chain)
10
+ # Use this config when running on Docker
11
+ # demo.launch(server_name="0.0.0.0", server_port=7000)
12
+ # To run on local machine
13
+ demo.launch(inline=False)
data/WHR2023.csv ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Country name,Ladder score,Standard error of ladder score,upperwhisker,lowerwhisker,Logged GDP per capita,Social support,Healthy life expectancy,Freedom to make life choices,Generosity,Perceptions of corruption,Ladder score in Dystopia,Explained by: Log GDP per capita,Explained by: Social support,Explained by: Healthy life expectancy,Explained by: Freedom to make life choices,Explained by: Generosity,Explained by: Perceptions of corruption,Dystopia + residual
2
+ Finland,7.804,0.036,7.875,7.733,10.792,0.969,71.150,0.961,-0.019,0.182,1.778,1.888,1.585,0.535,0.772,0.126,0.535,2.363
3
+ Denmark,7.586,0.041,7.667,7.506,10.962,0.954,71.250,0.934,0.134,0.196,1.778,1.949,1.548,0.537,0.734,0.208,0.525,2.084
4
+ Iceland,7.530,0.049,7.625,7.434,10.896,0.983,72.050,0.936,0.211,0.668,1.778,1.926,1.620,0.559,0.738,0.250,0.187,2.250
5
+ Israel,7.473,0.032,7.535,7.411,10.639,0.943,72.697,0.809,-0.023,0.708,1.778,1.833,1.521,0.577,0.569,0.124,0.158,2.691
6
+ Netherlands,7.403,0.029,7.460,7.346,10.942,0.930,71.550,0.887,0.213,0.379,1.778,1.942,1.488,0.545,0.672,0.251,0.394,2.110
7
+ Sweden,7.395,0.037,7.468,7.322,10.883,0.939,72.150,0.948,0.165,0.202,1.778,1.921,1.510,0.562,0.754,0.225,0.520,1.903
8
+ Norway,7.315,0.044,7.402,7.229,11.088,0.943,71.500,0.947,0.141,0.283,1.778,1.994,1.521,0.544,0.752,0.212,0.463,1.829
9
+ Switzerland,7.240,0.043,7.324,7.156,11.164,0.920,72.900,0.891,0.027,0.266,1.778,2.022,1.463,0.582,0.678,0.151,0.475,1.870
10
+ Luxembourg,7.228,0.069,7.363,7.093,11.660,0.879,71.675,0.915,0.024,0.345,1.778,2.200,1.357,0.549,0.710,0.149,0.418,1.845
11
+ New Zealand,7.123,0.038,7.198,7.048,10.662,0.952,70.350,0.887,0.175,0.271,1.778,1.842,1.544,0.513,0.672,0.230,0.471,1.852
12
+ Austria,7.097,0.040,7.176,7.018,10.899,0.888,71.150,0.855,0.102,0.497,1.778,1.927,1.382,0.535,0.630,0.191,0.310,2.124
13
+ Australia,7.095,0.044,7.180,7.009,10.821,0.934,71.050,0.890,0.198,0.496,1.778,1.899,1.497,0.532,0.677,0.242,0.310,1.938
14
+ Canada,6.961,0.042,7.042,6.879,10.773,0.929,71.400,0.874,0.153,0.420,1.778,1.881,1.484,0.541,0.656,0.218,0.364,1.815
15
+ Ireland,6.911,0.044,6.996,6.825,11.527,0.905,71.300,0.874,0.092,0.358,1.778,2.152,1.425,0.539,0.656,0.186,0.409,1.545
16
+ United States,6.894,0.047,6.986,6.802,11.048,0.919,65.850,0.800,0.137,0.689,1.778,1.980,1.460,0.390,0.557,0.210,0.172,2.124
17
+ Germany,6.892,0.049,6.989,6.795,10.879,0.896,71.300,0.846,0.030,0.420,1.778,1.919,1.401,0.539,0.618,0.153,0.365,1.898
18
+ Belgium,6.859,0.034,6.926,6.793,10.844,0.915,70.899,0.825,0.001,0.549,1.778,1.907,1.449,0.528,0.590,0.137,0.273,1.976
19
+ Czechia,6.845,0.044,6.931,6.759,10.611,0.953,69.050,0.903,0.040,0.859,1.778,1.823,1.544,0.477,0.693,0.158,0.050,2.099
20
+ United Kingdom,6.796,0.042,6.877,6.714,10.704,0.882,70.300,0.852,0.253,0.454,1.778,1.857,1.366,0.511,0.626,0.272,0.340,1.822
21
+ Lithuania,6.763,0.044,6.849,6.677,10.568,0.939,67.397,0.748,-0.145,0.805,1.778,1.808,1.511,0.432,0.487,0.059,0.089,2.377
22
+ France,6.661,0.038,6.735,6.588,10.701,0.909,72.300,0.819,-0.100,0.553,1.778,1.856,1.433,0.566,0.582,0.083,0.270,1.872
23
+ Slovenia,6.650,0.051,6.750,6.550,10.588,0.951,71.052,0.913,0.014,0.771,1.778,1.815,1.539,0.532,0.707,0.144,0.113,1.799
24
+ Costa Rica,6.609,0.052,6.710,6.507,9.952,0.872,70.000,0.895,-0.070,0.768,1.778,1.587,1.340,0.503,0.683,0.099,0.116,2.281
25
+ Romania,6.589,0.052,6.690,6.488,10.339,0.848,67.051,0.856,-0.172,0.929,1.778,1.726,1.280,0.423,0.631,0.044,0.000,2.485
26
+ Singapore,6.587,0.068,6.720,6.454,11.571,0.878,73.800,0.878,0.063,0.146,1.778,2.168,1.354,0.607,0.660,0.170,0.561,1.067
27
+ United Arab Emirates,6.571,0.043,6.656,6.486,11.145,0.826,66.243,0.942,0.096,0.584,1.778,2.015,1.223,0.401,0.745,0.188,0.247,1.752
28
+ Taiwan Province of China,6.535,0.047,6.627,6.444,10.797,0.884,69.600,0.804,-0.129,0.681,1.778,1.890,1.372,0.492,0.562,0.067,0.178,1.974
29
+ Uruguay,6.494,0.046,6.583,6.404,10.037,0.913,67.500,0.895,-0.065,0.575,1.778,1.617,1.445,0.435,0.683,0.102,0.254,1.958
30
+ Slovakia,6.469,0.056,6.578,6.360,10.353,0.953,68.838,0.753,-0.016,0.898,1.778,1.731,1.544,0.472,0.494,0.128,0.022,2.078
31
+ Saudi Arabia,6.463,0.061,6.581,6.344,10.715,0.884,64.399,0.894,-0.081,0.691,1.778,1.861,1.370,0.351,0.682,0.093,0.170,1.936
32
+ Estonia,6.455,0.040,6.534,6.377,10.541,0.946,69.650,0.929,0.032,0.409,1.778,1.798,1.526,0.494,0.728,0.153,0.372,1.383
33
+ Spain,6.436,0.042,6.519,6.354,10.540,0.932,72.350,0.782,-0.066,0.711,1.778,1.798,1.491,0.567,0.533,0.101,0.157,1.789
34
+ Italy,6.405,0.054,6.511,6.298,10.634,0.882,72.050,0.711,-0.074,0.842,1.778,1.832,1.365,0.559,0.438,0.097,0.063,2.052
35
+ Kosovo,6.368,0.060,6.485,6.250,9.359,0.844,65.195,0.861,0.259,0.866,1.778,1.374,1.269,0.372,0.639,0.275,0.045,2.393
36
+ Chile,6.334,0.046,6.424,6.243,10.114,0.889,70.300,0.792,-0.011,0.823,1.778,1.645,1.384,0.511,0.546,0.131,0.076,2.040
37
+ Mexico,6.330,0.057,6.441,6.218,9.850,0.804,65.800,0.856,-0.094,0.768,1.778,1.550,1.169,0.389,0.632,0.086,0.115,2.389
38
+ Malta,6.300,0.045,6.388,6.212,10.661,0.923,71.600,0.886,0.119,0.729,1.778,1.841,1.468,0.547,0.671,0.200,0.143,1.429
39
+ Panama,6.265,0.081,6.424,6.105,10.305,0.896,68.950,0.855,-0.133,0.878,1.778,1.714,1.402,0.475,0.630,0.065,0.036,1.943
40
+ Poland,6.260,0.042,6.343,6.177,10.453,0.925,69.049,0.765,-0.031,0.736,1.778,1.767,1.474,0.477,0.511,0.120,0.139,1.772
41
+ Nicaragua,6.259,0.076,6.408,6.109,8.618,0.853,65.650,0.877,0.021,0.625,1.778,1.109,1.292,0.385,0.660,0.148,0.218,2.448
42
+ Latvia,6.213,0.042,6.295,6.131,10.370,0.937,66.400,0.818,-0.056,0.830,1.778,1.737,1.505,0.405,0.580,0.107,0.071,1.808
43
+ Bahrain,6.173,0.100,6.369,5.977,10.776,0.844,65.825,0.944,0.117,0.737,1.778,1.883,1.269,0.389,0.748,0.199,0.138,1.546
44
+ Guatemala,6.150,0.108,6.362,5.939,9.116,0.812,62.900,0.856,-0.057,0.837,1.778,1.287,1.188,0.310,0.631,0.106,0.066,2.562
45
+ Kazakhstan,6.144,0.048,6.239,6.049,10.166,0.931,65.802,0.853,0.000,0.721,1.778,1.664,1.491,0.389,0.628,0.136,0.149,1.688
46
+ Serbia,6.144,0.079,6.299,5.988,9.854,0.873,67.088,0.845,0.204,0.816,1.778,1.552,1.343,0.424,0.617,0.246,0.081,1.881
47
+ Cyprus,6.130,0.054,6.236,6.024,10.611,0.826,72.802,0.724,-0.060,0.860,1.778,1.824,1.224,0.580,0.455,0.104,0.050,1.893
48
+ Japan,6.129,0.042,6.211,6.047,10.616,0.894,74.349,0.799,-0.237,0.640,1.778,1.825,1.396,0.622,0.556,0.009,0.207,1.513
49
+ Croatia,6.125,0.057,6.237,6.013,10.341,0.917,68.950,0.757,-0.093,0.925,1.778,1.727,1.455,0.475,0.500,0.087,0.003,1.880
50
+ Brazil,6.125,0.065,6.252,5.997,9.582,0.836,65.749,0.801,-0.009,0.738,1.778,1.454,1.250,0.387,0.558,0.131,0.137,2.205
51
+ El Salvador,6.122,0.069,6.257,5.986,9.089,0.755,65.597,0.918,-0.108,0.620,1.778,1.278,1.044,0.383,0.713,0.079,0.222,2.403
52
+ Hungary,6.041,0.055,6.149,5.933,10.419,0.943,67.500,0.758,-0.059,0.839,1.778,1.754,1.519,0.435,0.501,0.105,0.065,1.663
53
+ Argentina,6.024,0.063,6.147,5.900,9.959,0.891,67.200,0.823,-0.089,0.814,1.778,1.590,1.388,0.427,0.587,0.088,0.082,1.861
54
+ Honduras,6.023,0.089,6.196,5.849,8.635,0.766,64.063,0.843,0.097,0.843,1.778,1.115,1.072,0.341,0.613,0.189,0.062,2.631
55
+ Uzbekistan,6.014,0.059,6.130,5.899,8.948,0.875,65.301,0.938,0.230,0.638,1.778,1.227,1.347,0.375,0.740,0.260,0.208,1.856
56
+ Malaysia,6.012,0.079,6.167,5.858,10.169,0.799,65.662,0.877,0.160,0.758,1.778,1.665,1.155,0.385,0.659,0.222,0.122,1.804
57
+ Portugal,5.968,0.055,6.076,5.860,10.429,0.878,71.250,0.902,-0.196,0.878,1.778,1.758,1.356,0.537,0.693,0.031,0.037,1.556
58
+ South Korea,5.951,0.045,6.040,5.862,10.693,0.812,73.650,0.717,-0.046,0.701,1.778,1.853,1.188,0.603,0.446,0.112,0.163,1.587
59
+ Greece,5.931,0.048,6.024,5.838,10.288,0.835,71.150,0.568,-0.240,0.793,1.778,1.708,1.247,0.535,0.248,0.008,0.097,2.089
60
+ Mauritius,5.902,0.057,6.013,5.791,9.957,0.888,63.850,0.813,-0.028,0.775,1.778,1.589,1.382,0.336,0.574,0.121,0.110,1.790
61
+ Thailand,5.843,0.064,5.969,5.717,9.751,0.874,68.450,0.850,0.289,0.910,1.778,1.515,1.344,0.461,0.624,0.291,0.013,1.594
62
+ Mongolia,5.840,0.046,5.930,5.750,9.372,0.933,60.500,0.701,0.190,0.849,1.778,1.379,1.494,0.244,0.425,0.239,0.058,2.001
63
+ Kyrgyzstan,5.825,0.045,5.913,5.737,8.486,0.911,66.852,0.934,0.181,0.904,1.778,1.061,1.439,0.417,0.735,0.234,0.018,1.920
64
+ Moldova,5.819,0.052,5.922,5.717,9.499,0.857,65.299,0.840,-0.080,0.901,1.778,1.425,1.302,0.375,0.610,0.093,0.020,1.995
65
+ China,5.818,0.044,5.905,5.731,9.738,0.836,68.689,0.882,-0.041,0.727,1.778,1.510,1.249,0.468,0.666,0.115,0.145,1.666
66
+ Vietnam,5.763,0.052,5.865,5.662,9.287,0.821,65.502,0.939,-0.004,0.759,1.778,1.349,1.212,0.381,0.741,0.134,0.122,1.824
67
+ Paraguay,5.738,0.058,5.851,5.625,9.510,0.906,65.900,0.891,0.021,0.843,1.778,1.428,1.427,0.392,0.678,0.148,0.062,1.604
68
+ Montenegro,5.722,0.112,5.941,5.503,9.813,0.890,67.100,0.805,0.063,0.844,1.778,1.537,1.385,0.424,0.563,0.170,0.061,1.581
69
+ Jamaica,5.703,0.089,5.876,5.529,9.165,0.867,66.600,0.822,-0.106,0.875,1.778,1.305,1.329,0.411,0.587,0.079,0.039,1.954
70
+ Bolivia,5.684,0.057,5.797,5.572,8.985,0.811,63.599,0.868,-0.063,0.846,1.778,1.240,1.187,0.329,0.648,0.103,0.060,2.118
71
+ Russia,5.661,0.037,5.734,5.588,10.210,0.889,64.947,0.719,-0.030,0.801,1.778,1.680,1.383,0.366,0.449,0.120,0.091,1.572
72
+ Bosnia and Herzegovina,5.633,0.073,5.775,5.490,9.616,0.880,67.275,0.746,0.206,0.918,1.778,1.467,1.361,0.429,0.485,0.247,0.008,1.635
73
+ Colombia,5.630,0.060,5.747,5.514,9.584,0.822,69.350,0.804,-0.104,0.834,1.778,1.455,1.213,0.486,0.562,0.080,0.068,1.765
74
+ Dominican Republic,5.569,0.073,5.712,5.426,9.811,0.827,64.399,0.850,-0.099,0.657,1.778,1.536,1.227,0.351,0.623,0.083,0.195,1.553
75
+ Ecuador,5.559,0.063,5.682,5.436,9.270,0.806,69.000,0.802,-0.108,0.833,1.778,1.343,1.173,0.476,0.560,0.079,0.069,1.860
76
+ Peru,5.526,0.058,5.640,5.412,9.402,0.798,69.850,0.794,-0.119,0.892,1.778,1.390,1.153,0.499,0.549,0.073,0.027,1.835
77
+ Philippines,5.523,0.077,5.675,5.371,8.979,0.780,62.038,0.919,-0.060,0.732,1.778,1.238,1.108,0.286,0.714,0.104,0.141,1.931
78
+ Bulgaria,5.466,0.059,5.582,5.350,10.087,0.918,66.500,0.801,-0.057,0.911,1.778,1.635,1.457,0.408,0.557,0.106,0.013,1.289
79
+ Nepal,5.360,0.075,5.507,5.214,8.256,0.748,61.847,0.808,0.146,0.783,1.778,0.979,1.027,0.281,0.567,0.215,0.104,2.187
80
+ Armenia,5.342,0.066,5.470,5.213,9.615,0.790,67.789,0.796,-0.155,0.705,1.778,1.466,1.134,0.443,0.551,0.053,0.160,1.534
81
+ Tajikistan,5.330,0.062,5.452,5.207,8.237,0.836,62.226,0.832,-0.060,0.522,1.778,0.972,1.248,0.291,0.599,0.104,0.292,1.823
82
+ Algeria,5.329,0.062,5.451,5.207,9.300,0.855,66.549,0.571,-0.117,0.717,1.778,1.353,1.298,0.409,0.252,0.073,0.152,1.791
83
+ Hong Kong S.A.R. of China,5.308,0.048,5.403,5.214,10.966,0.817,77.280,0.687,-0.026,0.385,1.778,1.951,1.201,0.702,0.407,0.123,0.390,0.535
84
+ Albania,5.277,0.066,5.406,5.148,9.567,0.718,69.150,0.794,-0.007,0.878,1.778,1.449,0.951,0.480,0.549,0.133,0.037,1.678
85
+ Indonesia,5.277,0.059,5.392,5.161,9.385,0.804,63.048,0.880,0.531,0.876,1.778,1.384,1.169,0.314,0.663,0.422,0.038,1.288
86
+ South Africa,5.275,0.073,5.417,5.132,9.478,0.907,56.989,0.730,-0.087,0.902,1.778,1.417,1.428,0.149,0.464,0.090,0.019,1.708
87
+ Congo (Brazzaville),5.267,0.088,5.440,5.094,8.095,0.605,56.850,0.730,-0.004,0.739,1.778,0.921,0.665,0.145,0.464,0.134,0.136,2.802
88
+ North Macedonia,5.254,0.055,5.361,5.146,9.703,0.805,66.500,0.769,0.131,0.902,1.778,1.498,1.171,0.408,0.515,0.207,0.020,1.435
89
+ Venezuela,5.211,0.064,5.336,5.085,5.527,0.839,64.050,0.659,0.128,0.811,1.778,0.000,1.257,0.341,0.369,0.205,0.084,2.955
90
+ Laos,5.111,0.081,5.269,4.952,8.962,0.679,60.946,0.919,0.091,0.703,1.778,1.232,0.853,0.257,0.715,0.185,0.162,1.707
91
+ Georgia,5.109,0.056,5.219,5.000,9.646,0.716,64.950,0.786,-0.254,0.649,1.778,1.477,0.947,0.366,0.539,0.000,0.201,1.580
92
+ Guinea,5.072,0.072,5.213,4.931,7.880,0.649,54.185,0.659,0.125,0.787,1.778,0.844,0.776,0.072,0.369,0.204,0.102,2.705
93
+ Ukraine,5.071,0.059,5.187,4.956,9.314,0.878,64.550,0.795,0.240,0.907,1.778,1.358,1.354,0.355,0.551,0.265,0.016,1.172
94
+ Ivory Coast,5.053,0.074,5.198,4.907,8.576,0.572,55.953,0.733,0.003,0.746,1.778,1.094,0.584,0.120,0.467,0.138,0.131,2.519
95
+ Gabon,5.035,0.072,5.175,4.894,9.537,0.746,58.252,0.642,-0.187,0.786,1.778,1.438,1.021,0.183,0.346,0.036,0.102,1.908
96
+ Nigeria,4.981,0.080,5.136,4.825,8.496,0.740,54.891,0.718,0.073,0.911,1.778,1.065,1.007,0.092,0.448,0.176,0.013,2.181
97
+ Cameroon,4.973,0.071,5.112,4.834,8.217,0.686,55.847,0.686,0.015,0.846,1.778,0.965,0.871,0.118,0.405,0.144,0.059,2.411
98
+ Mozambique,4.954,0.116,5.181,4.727,7.116,0.692,51.530,0.851,0.047,0.660,1.778,0.570,0.885,0.000,0.625,0.161,0.192,2.519
99
+ Iraq,4.941,0.081,5.099,4.783,9.098,0.718,63.415,0.646,-0.005,0.876,1.778,1.281,0.953,0.324,0.351,0.134,0.038,1.861
100
+ State of Palestine,4.908,0.092,5.089,4.727,8.716,0.859,,0.694,-0.132,0.836,1.778,1.144,1.309,,0.416,0.065,0.067,
101
+ Morocco,4.903,0.061,5.023,4.783,8.973,0.553,63.901,0.787,-0.231,0.811,1.778,1.236,0.535,0.337,0.540,0.013,0.085,2.158
102
+ Iran,4.876,0.053,4.980,4.772,9.610,0.778,66.600,0.593,0.173,0.747,1.778,1.465,1.102,0.411,0.281,0.229,0.130,1.259
103
+ Senegal,4.855,0.065,4.983,4.727,8.155,0.629,59.999,0.772,0.011,0.846,1.778,0.943,0.727,0.231,0.519,0.142,0.060,2.234
104
+ Mauritania,4.724,0.147,5.011,4.437,8.591,0.644,60.475,0.622,-0.013,0.657,1.778,1.099,0.764,0.244,0.320,0.130,0.195,1.973
105
+ Burkina Faso,4.638,0.093,4.819,4.456,7.667,0.663,55.461,0.696,0.095,0.771,1.778,0.768,0.814,0.107,0.419,0.188,0.113,2.230
106
+ Namibia,4.631,0.069,4.766,4.496,9.121,0.787,56.851,0.669,-0.126,0.830,1.778,1.289,1.126,0.145,0.383,0.069,0.071,1.549
107
+ Turkiye,4.614,0.083,4.777,4.450,10.307,0.796,68.663,0.475,-0.077,0.795,1.778,1.714,1.148,0.467,0.125,0.095,0.096,0.969
108
+ Ghana,4.605,0.063,4.729,4.481,8.596,0.641,58.763,0.777,0.139,0.881,1.778,1.101,0.756,0.197,0.526,0.211,0.035,1.779
109
+ Pakistan,4.555,0.077,4.707,4.404,8.540,0.601,57.313,0.766,0.008,0.787,1.778,1.081,0.657,0.158,0.511,0.141,0.102,1.907
110
+ Niger,4.501,0.108,4.712,4.291,7.091,0.590,56.550,0.788,0.032,0.734,1.778,0.561,0.628,0.137,0.540,0.154,0.140,2.341
111
+ Tunisia,4.497,0.053,4.601,4.393,9.244,0.730,67.000,0.576,-0.213,0.907,1.778,1.333,0.981,0.422,0.259,0.022,0.016,1.463
112
+ Kenya,4.487,0.066,4.616,4.357,8.458,0.690,58.499,0.696,0.288,0.852,1.778,1.051,0.881,0.190,0.418,0.291,0.055,1.601
113
+ Sri Lanka,4.442,0.083,4.603,4.280,9.491,0.826,67.150,0.787,-0.030,0.808,1.778,1.422,1.224,0.426,0.539,0.120,0.086,0.625
114
+ Uganda,4.432,0.089,4.607,4.258,7.716,0.794,58.913,0.701,0.114,0.857,1.778,0.785,1.144,0.201,0.425,0.197,0.051,1.628
115
+ Chad,4.397,0.121,4.633,4.160,7.261,0.722,53.125,0.677,0.221,0.807,1.778,0.622,0.962,0.043,0.393,0.255,0.088,2.034
116
+ Cambodia,4.393,0.059,4.508,4.279,8.385,0.747,61.900,0.958,0.073,0.857,1.778,1.025,1.024,0.283,0.768,0.176,0.051,1.068
117
+ Benin,4.374,0.066,4.504,4.244,8.103,0.437,56.095,0.743,-0.043,0.576,1.778,0.924,0.242,0.124,0.481,0.114,0.253,2.235
118
+ Myanmar,4.372,0.082,4.533,4.212,8.404,0.787,61.388,0.727,0.491,0.658,1.778,1.032,1.125,0.269,0.460,0.400,0.194,0.893
119
+ Bangladesh,4.282,0.068,4.416,4.148,8.685,0.544,64.548,0.845,0.005,0.698,1.778,1.133,0.513,0.355,0.617,0.139,0.165,1.361
120
+ Gambia,4.279,0.105,4.484,4.075,7.648,0.584,57.900,0.596,0.364,0.883,1.778,0.761,0.614,0.174,0.286,0.332,0.033,2.081
121
+ Mali,4.198,0.062,4.319,4.076,7.655,0.593,55.403,0.713,-0.028,0.846,1.778,0.763,0.637,0.106,0.441,0.121,0.059,2.070
122
+ Egypt,4.170,0.059,4.287,4.054,9.367,0.726,63.503,0.732,-0.183,0.580,1.778,1.377,0.972,0.326,0.467,0.038,0.250,0.740
123
+ Togo,4.137,0.077,4.289,3.986,7.673,0.595,57.449,0.657,0.024,0.740,1.778,0.770,0.642,0.161,0.367,0.149,0.136,1.913
124
+ Jordan,4.120,0.062,4.242,3.997,9.130,0.729,67.600,0.770,-0.150,0.687,1.778,1.292,0.980,0.438,0.517,0.056,0.173,0.663
125
+ Ethiopia,4.091,0.093,4.273,3.908,7.739,0.782,60.698,0.720,0.273,0.789,1.778,0.793,1.114,0.250,0.451,0.283,0.101,1.099
126
+ Liberia,4.042,0.144,4.325,3.760,7.277,0.596,56.700,0.735,0.154,0.830,1.778,0.628,0.644,0.141,0.471,0.219,0.071,1.869
127
+ India,4.036,0.029,4.092,3.980,8.759,0.608,60.777,0.897,0.072,0.774,1.778,1.159,0.674,0.252,0.685,0.175,0.111,0.979
128
+ Madagascar,4.019,0.092,4.199,3.839,7.290,0.650,58.050,0.522,0.075,0.742,1.778,0.632,0.779,0.178,0.187,0.177,0.134,1.932
129
+ Zambia,3.982,0.094,4.167,3.797,8.074,0.694,55.032,0.791,0.098,0.818,1.778,0.914,0.890,0.095,0.545,0.189,0.080,1.270
130
+ Tanzania,3.694,0.075,3.840,3.547,7.857,0.653,59.401,0.838,0.182,0.554,1.778,0.836,0.787,0.214,0.607,0.234,0.269,0.747
131
+ Comoros,3.545,0.117,3.774,3.317,8.075,0.471,59.425,0.470,-0.014,0.727,1.778,0.914,0.327,0.215,0.117,0.129,0.145,1.699
132
+ Malawi,3.495,0.090,3.671,3.320,7.302,0.531,58.475,0.750,0.005,0.749,1.778,0.637,0.479,0.189,0.490,0.139,0.129,1.432
133
+ Botswana,3.435,0.136,3.702,3.168,9.629,0.753,54.725,0.742,-0.215,0.830,1.778,1.471,1.041,0.087,0.480,0.021,0.071,0.264
134
+ Congo (Kinshasa),3.207,0.095,3.394,3.020,7.007,0.652,55.375,0.664,0.086,0.834,1.778,0.531,0.784,0.105,0.375,0.183,0.068,1.162
135
+ Zimbabwe,3.204,0.061,3.323,3.084,7.641,0.690,54.050,0.654,-0.046,0.766,1.778,0.758,0.881,0.069,0.363,0.112,0.117,0.905
136
+ Sierra Leone,3.138,0.082,3.299,2.976,7.394,0.555,54.900,0.660,0.105,0.858,1.778,0.670,0.540,0.092,0.371,0.193,0.051,1.221
137
+ Lebanon,2.392,0.044,2.479,2.305,9.478,0.530,66.149,0.474,-0.141,0.891,1.778,1.417,0.476,0.398,0.123,0.061,0.027,-0.110
138
+ Afghanistan,1.859,0.033,1.923,1.795,7.324,0.341,54.712,0.382,-0.081,0.847,1.778,0.645,0.000,0.087,0.000,0.093,0.059,0.976
gradio_app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, sys
2
+ from os.path import dirname as up
3
+
4
+ sys.path.append(os.path.abspath(os.path.join(up(__file__), os.pardir)))
5
+
6
+ from utils import *
7
+
8
+
9
+ df = pd.read_csv(CSV_FILE_PATH)
10
+
11
+ def gradio_interface(helper_function):
12
+ def clear_fields(query, output):
13
+ return "", ""
14
+
15
+ with gr.Blocks() as demo:
16
+ gr.Markdown("""
17
+ <h1> Question and Answer Bot for World Happiness Report 2023 </h1>
18
+
19
+ Only first 5 rows shown. To check out whole dataset:
20
+ https://www.kaggle.com/datasets/ajaypalsinghlo/world-happiness-report-2023
21
+ """)
22
+ with gr.Row():
23
+ with gr.Column():
24
+ inputs = [gr.Dataframe(df, row_count=(5, "fixed"), max_rows=5, label="World Happiness Report 2023")]
25
+ query = gr.Text(label="Ask question about one or more countries.", placeholder="Type your question here", lines=4)
26
+ btn_submit = gr.Button("Submit")
27
+ with gr.Column():
28
+ output = gr.TextArea(label="Response to the query.", lines=18)
29
+ btn_clear = gr.Button("Clear")
30
+ btn_submit.click(helper_function, inputs=[query], outputs=[output])
31
+ btn_clear.click(clear_fields, inputs=[query, output], outputs=[query, output])
32
+
33
+ return demo
requirements.txt ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.1.0
2
+ aiohttp==3.8.4
3
+ aiosignal==1.3.1
4
+ altair==4.2.2
5
+ anyio==3.6.2
6
+ async-timeout==4.0.2
7
+ attrs==22.2.0
8
+ backoff==2.2.1
9
+ certifi==2022.12.7
10
+ charset-normalizer==3.1.0
11
+ chromadb==0.3.20
12
+ click==8.1.3
13
+ clickhouse-connect==0.5.18
14
+ contourpy==1.0.7
15
+ cycler==0.11.0
16
+ dataclasses-json==0.5.7
17
+ duckdb==0.7.1
18
+ entrypoints==0.4
19
+ fastapi==0.95.0
20
+ ffmpy==0.3.0
21
+ filelock==3.10.7
22
+ fonttools==4.39.3
23
+ frozenlist==1.3.3
24
+ fsspec==2023.3.0
25
+ gradio==3.24.1
26
+ gradio_client==0.0.5
27
+ h11==0.14.0
28
+ hnswlib==0.7.0
29
+ httpcore==0.16.3
30
+ httptools==0.5.0
31
+ httpx==0.23.3
32
+ huggingface-hub==0.13.3
33
+ idna==3.4
34
+ Jinja2==3.1.2
35
+ joblib==1.2.0
36
+ jsonschema==4.17.3
37
+ kiwisolver==1.4.4
38
+ langchain==0.0.130
39
+ linkify-it-py==2.0.0
40
+ lz4==4.3.2
41
+ markdown-it-py==2.2.0
42
+ MarkupSafe==2.1.2
43
+ marshmallow==3.19.0
44
+ marshmallow-enum==1.5.1
45
+ matplotlib==3.7.1
46
+ mdit-py-plugins==0.3.3
47
+ mdurl==0.1.2
48
+ monotonic==1.6
49
+ mpmath==1.3.0
50
+ multidict==6.0.4
51
+ mypy-extensions==1.0.0
52
+ networkx==3.0
53
+ nltk==3.8.1
54
+ numpy==1.24.2
55
+ openai==0.27.2
56
+ orjson==3.8.9
57
+ packaging==23.0
58
+ pandas==2.0.0
59
+ Pillow==9.5.0
60
+ pip==23.0.1
61
+ posthog==2.4.2
62
+ pydantic==1.10.7
63
+ pydub==0.25.1
64
+ pyparsing==3.0.9
65
+ pyrsistent==0.19.3
66
+ python-dateutil==2.8.2
67
+ python-dotenv==1.0.0
68
+ python-multipart==0.0.6
69
+ pytz==2023.3
70
+ PyYAML==6.0
71
+ regex==2023.3.23
72
+ requests==2.28.2
73
+ rfc3986==1.5.0
74
+ scikit-learn==1.2.2
75
+ scipy==1.10.1
76
+ semantic-version==2.10.0
77
+ sentence-transformers==2.2.2
78
+ sentencepiece==0.1.97
79
+ setuptools==67.6.1
80
+ six==1.16.0
81
+ sniffio==1.3.0
82
+ SQLAlchemy==1.4.47
83
+ starlette==0.26.1
84
+ sympy==1.11.1
85
+ tenacity==8.2.2
86
+ threadpoolctl==3.1.0
87
+ tokenizers==0.13.2
88
+ toolz==0.12.0
89
+ torch==2.0.0
90
+ torchvision==0.15.1
91
+ tqdm==4.65.0
92
+ transformers==4.27.4
93
+ typing_extensions==4.5.0
94
+ typing-inspect==0.8.0
95
+ tzdata==2023.3
96
+ uc-micro-py==1.0.1
97
+ urllib3==1.26.15
98
+ uvicorn==0.21.1
99
+ uvloop==0.17.0
100
+ watchfiles==0.19.0
101
+ websockets==11.0
102
+ wheel==0.40.0
103
+ yarl==1.8.2
104
+ zstandard==0.20.0
utils/__init__.py ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ from utils.constants import *
2
+ from utils.helper import *
utils/constants.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import os, sys
2
+ from os.path import dirname as up
3
+
4
+ sys.path.append(os.path.abspath(os.path.join(up(__file__), os.pardir)))
5
+
6
+
7
+ OPENAI_API_KEY = "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"
8
+ # OPENAI_API_KEY = ""
9
+ CSV_FILE_PATH = "data/WHR2023.csv"
utils/helper.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, sys
2
+ from os.path import dirname as up
3
+
4
+ sys.path.append(os.path.abspath(os.path.join(up(__file__), os.pardir)))
5
+
6
+ from langchain.document_loaders import CSVLoader
7
+ from langchain.indexes import VectorstoreIndexCreator
8
+ from langchain.chains import RetrievalQA
9
+ from langchain.llms import OpenAI
10
+ import os
11
+
12
+ import gradio as gr
13
+ import pandas as pd
14
+
15
+ from utils.constants import *
16
+
17
+ os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
18
+
19
+ # Load the documents
20
+ loader = CSVLoader(file_path=CSV_FILE_PATH)
21
+
22
+ # Create an index using the loaded documents
23
+ index_creator = VectorstoreIndexCreator()
24
+ docsearch = index_creator.from_loaders([loader])
25
+
26
+ # Create a question-answering chain using the index
27
+ chain = RetrievalQA.from_chain_type(
28
+ llm=OpenAI(),
29
+ chain_type="stuff",
30
+ retriever=docsearch.vectorstore.as_retriever(),
31
+ input_key="question",
32
+ )
33
+
34
+ def return_response_chain(query: str):
35
+ response = chain({"question": query})
36
+ return response['result']
37
+
38
+ def clear_fields(query: str, output: str):
39
+ query = ""
40
+ output = ""
41
+
42
+ # if __name__ == "__main__":
43
+ # # Pass a query to the chain
44
+ # query = "How does UAE compare with USA in terms of gdp?"
45
+ # response = chain({"question": query})
46
+ # print(response['result'])