Spaces:
Running
Running
Commit
•
8cb6315
1
Parent(s):
0b65517
Update app.py
Browse files
app.py
CHANGED
@@ -69,23 +69,23 @@ k = 0
|
|
69 |
# print(result)
|
70 |
# return result
|
71 |
|
72 |
-
def get_location(ip_address):
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
|
90 |
# def get_ip():
|
91 |
# response = requests.get('https://api64.ipify.org?format=json').json()
|
@@ -102,6 +102,31 @@ def get_location(ip_address):
|
|
102 |
# "country": response.get("country_name")
|
103 |
# }
|
104 |
# return location_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
def generate_emotion(article):
|
107 |
text = "Input sentence: "
|
@@ -131,14 +156,19 @@ def generate_emotion(article):
|
|
131 |
def save_data_and_sendmail(article,output):
|
132 |
try:
|
133 |
print("welcome")
|
134 |
-
|
135 |
# ip_address = get_device_ip_address()
|
136 |
-
ip_address=str(request.remote_addr)
|
137 |
-
print(ip_address)
|
138 |
-
location = get_location(ip_address)
|
139 |
# location = get_location(ip_address)
|
140 |
# print(ip_address)
|
141 |
-
|
|
|
|
|
|
|
|
|
|
|
142 |
with open(DATA_FILE, "a") as f:
|
143 |
writer = csv.writer(f)
|
144 |
# write the data
|
@@ -150,10 +180,9 @@ def save_data_and_sendmail(article,output):
|
|
150 |
# # url = 'http://pragnakalpdev33.pythonanywhere.com/HF_space_question_generator'
|
151 |
# myobj = {'article': article,'total_que': num_que,'gen_que':result,'ip_addr':hostname.get("ip_addr",""),'host':hostname.get("host","")}
|
152 |
# x = requests.post(url, json = myobj)
|
153 |
-
|
154 |
-
print(location)
|
155 |
url = 'https://pragnakalpdev33.pythonanywhere.com/HF_space_bert_base_ner'
|
156 |
-
myobj = {'article': article,'gen_text':output,'ip_addr':ip_address}
|
157 |
x = requests.post(url, json = myobj)
|
158 |
|
159 |
return "Successfully save data"
|
|
|
69 |
# print(result)
|
70 |
# return result
|
71 |
|
72 |
+
# def get_location(ip_address):
|
73 |
+
# ip=ip_address
|
74 |
+
# # ip=str(request.remote_addr)
|
75 |
+
# req_data={
|
76 |
+
# "ip":ip,
|
77 |
+
# "token":"pkml123"
|
78 |
+
# }
|
79 |
+
# url = "https://demos.pragnakalp.com/get-ip-location"
|
80 |
|
81 |
+
# # req_data=json.dumps(req_data)
|
82 |
+
# # print("req_data",req_data)
|
83 |
+
# headers = {'Content-Type': 'application/json'}
|
84 |
|
85 |
+
# response = requests.request("POST", url, headers=headers, data=json.dumps(req_data))
|
86 |
+
# response = response.json()
|
87 |
+
# print("response======>>",response)
|
88 |
+
# return response
|
89 |
|
90 |
# def get_ip():
|
91 |
# response = requests.get('https://api64.ipify.org?format=json').json()
|
|
|
102 |
# "country": response.get("country_name")
|
103 |
# }
|
104 |
# return location_data
|
105 |
+
|
106 |
+
|
107 |
+
def getIP():
|
108 |
+
d = str(urlopen('http://checkip.dyndns.com/')
|
109 |
+
.read())
|
110 |
+
|
111 |
+
return r.compile(r'Address: (\d+\.\d+\.\d+\.\d+)').search(d).group(1)
|
112 |
+
|
113 |
+
def get_location(ip_addr):
|
114 |
+
ip=ip_addr
|
115 |
+
|
116 |
+
req_data={
|
117 |
+
"ip":ip,
|
118 |
+
"token":"pkml123"
|
119 |
+
}
|
120 |
+
url = "https://demos.pragnakalp.com/get-ip-location"
|
121 |
+
|
122 |
+
# req_data=json.dumps(req_data)
|
123 |
+
# print("req_data",req_data)
|
124 |
+
headers = {'Content-Type': 'application/json'}
|
125 |
+
|
126 |
+
response = requests.request("POST", url, headers=headers, data=json.dumps(req_data))
|
127 |
+
response = response.json()
|
128 |
+
print("response======>>",response)
|
129 |
+
return response
|
130 |
|
131 |
def generate_emotion(article):
|
132 |
text = "Input sentence: "
|
|
|
156 |
def save_data_and_sendmail(article,output):
|
157 |
try:
|
158 |
print("welcome")
|
159 |
+
ip_address = ''
|
160 |
# ip_address = get_device_ip_address()
|
161 |
+
# ip_address=str(request.remote_addr)
|
162 |
+
# print(ip_address)
|
163 |
+
# location = get_location(ip_address)
|
164 |
# location = get_location(ip_address)
|
165 |
# print(ip_address)
|
166 |
+
|
167 |
+
ip_address= getIP()
|
168 |
+
print(ip_address)
|
169 |
+
location = get_location(ip_address)
|
170 |
+
print(location)
|
171 |
+
add_csv = [article,output,ip_address,location]
|
172 |
with open(DATA_FILE, "a") as f:
|
173 |
writer = csv.writer(f)
|
174 |
# write the data
|
|
|
180 |
# # url = 'http://pragnakalpdev33.pythonanywhere.com/HF_space_question_generator'
|
181 |
# myobj = {'article': article,'total_que': num_que,'gen_que':result,'ip_addr':hostname.get("ip_addr",""),'host':hostname.get("host","")}
|
182 |
# x = requests.post(url, json = myobj)
|
183 |
+
|
|
|
184 |
url = 'https://pragnakalpdev33.pythonanywhere.com/HF_space_bert_base_ner'
|
185 |
+
myobj = {'article': article,'gen_text':output,'ip_addr':ip_address,"location":location}
|
186 |
x = requests.post(url, json = myobj)
|
187 |
|
188 |
return "Successfully save data"
|