Spaces:
Running
Running
Commit ·
1befc82
1
Parent(s): 58dade5
Update app.py
Browse files
app.py
CHANGED
|
@@ -48,59 +48,59 @@ bert_ner_model = os.path.join(cwd)
|
|
| 48 |
Entities_Found =[]
|
| 49 |
Entity_Types = []
|
| 50 |
k = 0
|
| 51 |
-
def get_device_ip_address():
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
#
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
|
| 80 |
-
#
|
| 81 |
-
#
|
| 82 |
-
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
|
| 89 |
# def get_ip():
|
| 90 |
# response = requests.get('https://api64.ipify.org?format=json').json()
|
| 91 |
# return response["ip"]
|
| 92 |
|
| 93 |
|
| 94 |
-
def get_location(ip_addr):
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
|
| 105 |
def generate_emotion(article):
|
| 106 |
text = "Input sentence: "
|
|
@@ -130,8 +130,10 @@ def generate_emotion(article):
|
|
| 130 |
def save_data_and_sendmail(article,output):
|
| 131 |
try:
|
| 132 |
print("welcome")
|
| 133 |
-
ip_address = ''
|
| 134 |
-
ip_address = get_device_ip_address()
|
|
|
|
|
|
|
| 135 |
# location = get_location(ip_address)
|
| 136 |
print(ip_address)
|
| 137 |
add_csv = [article,output,ip_address]
|
|
@@ -146,7 +148,7 @@ def save_data_and_sendmail(article,output):
|
|
| 146 |
# # url = 'http://pragnakalpdev33.pythonanywhere.com/HF_space_question_generator'
|
| 147 |
# myobj = {'article': article,'total_que': num_que,'gen_que':result,'ip_addr':hostname.get("ip_addr",""),'host':hostname.get("host","")}
|
| 148 |
# x = requests.post(url, json = myobj)
|
| 149 |
-
location = get_location(ip_addr)
|
| 150 |
print(location)
|
| 151 |
url = 'https://pragnakalpdev33.pythonanywhere.com/HF_space_bert_base_ner'
|
| 152 |
myobj = {'article': article,'gen_text':output,'ip_addr':ip_address}
|
|
|
|
| 48 |
Entities_Found =[]
|
| 49 |
Entity_Types = []
|
| 50 |
k = 0
|
| 51 |
+
# def get_device_ip_address():
|
| 52 |
|
| 53 |
+
# if os.name == "nt":
|
| 54 |
+
# result = "Running on Windows"
|
| 55 |
+
# hostname = socket.gethostname()
|
| 56 |
+
# ip_address = socket.gethostbyname(hostname)
|
| 57 |
+
# return ip_address
|
| 58 |
+
# elif os.name == "posix":
|
| 59 |
+
# gw = os.popen("ip -4 route show default").read().split()
|
| 60 |
+
# s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
| 61 |
+
# s.connect((gw[2], 0))
|
| 62 |
+
# ip_address = s.getsockname()[0]
|
| 63 |
+
# gateway = gw[2]
|
| 64 |
+
# host = socket.gethostname()
|
| 65 |
+
# return ip_address
|
| 66 |
+
# else:
|
| 67 |
+
# result['id'] = os.name + " not supported yet."
|
| 68 |
+
# print(result)
|
| 69 |
+
# return result
|
| 70 |
|
| 71 |
+
def get_location(ip_addr):
|
| 72 |
+
ip=ip_addr
|
| 73 |
+
# ip=str(request.remote_addr)
|
| 74 |
+
req_data={
|
| 75 |
+
"ip":ip,
|
| 76 |
+
"token":"pkml123"
|
| 77 |
+
}
|
| 78 |
+
url = "https://demos.pragnakalp.com/get-ip-location"
|
| 79 |
|
| 80 |
+
# req_data=json.dumps(req_data)
|
| 81 |
+
# print("req_data",req_data)
|
| 82 |
+
headers = {'Content-Type': 'application/json'}
|
| 83 |
|
| 84 |
+
response = requests.request("POST", url, headers=headers, data=json.dumps(req_data))
|
| 85 |
+
response = response.json()
|
| 86 |
+
print("response======>>",response)
|
| 87 |
+
return response
|
| 88 |
|
| 89 |
# def get_ip():
|
| 90 |
# response = requests.get('https://api64.ipify.org?format=json').json()
|
| 91 |
# return response["ip"]
|
| 92 |
|
| 93 |
|
| 94 |
+
# def get_location(ip_addr):
|
| 95 |
+
# ip_address = ip_addr
|
| 96 |
+
# response = requests.get(f'https://ipapi.co/{ip_address}/json/').json()
|
| 97 |
+
# location_data = {
|
| 98 |
+
# "ip": ip_address,
|
| 99 |
+
# "city": response.get("city"),
|
| 100 |
+
# "region": response.get("region"),
|
| 101 |
+
# "country": response.get("country_name")
|
| 102 |
+
# }
|
| 103 |
+
# return location_data
|
| 104 |
|
| 105 |
def generate_emotion(article):
|
| 106 |
text = "Input sentence: "
|
|
|
|
| 130 |
def save_data_and_sendmail(article,output):
|
| 131 |
try:
|
| 132 |
print("welcome")
|
| 133 |
+
# ip_address = ''
|
| 134 |
+
# ip_address = get_device_ip_address()
|
| 135 |
+
ip_address=str(request.remote_addr)
|
| 136 |
+
location = get_location(ip_address)
|
| 137 |
# location = get_location(ip_address)
|
| 138 |
print(ip_address)
|
| 139 |
add_csv = [article,output,ip_address]
|
|
|
|
| 148 |
# # url = 'http://pragnakalpdev33.pythonanywhere.com/HF_space_question_generator'
|
| 149 |
# myobj = {'article': article,'total_que': num_que,'gen_que':result,'ip_addr':hostname.get("ip_addr",""),'host':hostname.get("host","")}
|
| 150 |
# x = requests.post(url, json = myobj)
|
| 151 |
+
# location = get_location(ip_addr)
|
| 152 |
print(location)
|
| 153 |
url = 'https://pragnakalpdev33.pythonanywhere.com/HF_space_bert_base_ner'
|
| 154 |
myobj = {'article': article,'gen_text':output,'ip_addr':ip_address}
|