Spaces:
Running
Running
Commit ·
0197658
1
Parent(s): e902a03
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,7 +21,7 @@ import huggingface_hub
|
|
| 21 |
import socket
|
| 22 |
|
| 23 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 24 |
-
DATASET_NAME = "
|
| 25 |
DATASET_REPO_URL = f"https://huggingface.co/datasets/pragnakalp/{DATASET_NAME}"
|
| 26 |
DATA_FILENAME = "bert_base_ner_logs.csv"
|
| 27 |
DATA_FILE = os.path.join("bert_base_ner_logs", DATA_FILENAME)
|
|
@@ -49,32 +49,45 @@ 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 |
-
result['ip_addr'] = ip_address
|
| 58 |
-
result['host'] = hostname
|
| 59 |
print(result)
|
| 60 |
-
return
|
| 61 |
elif os.name == "posix":
|
| 62 |
gw = os.popen("ip -4 route show default").read().split()
|
| 63 |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
| 64 |
s.connect((gw[2], 0))
|
| 65 |
-
|
| 66 |
gateway = gw[2]
|
| 67 |
host = socket.gethostname()
|
| 68 |
-
result['ip_addr'] = ipaddr
|
| 69 |
-
result['host'] = host
|
| 70 |
print(result)
|
| 71 |
-
return
|
| 72 |
else:
|
| 73 |
result['id'] = os.name + " not supported yet."
|
| 74 |
print(result)
|
| 75 |
return result
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
def generate_emotion(article):
|
| 79 |
text = "Input sentence: "
|
| 80 |
text += article
|
|
@@ -102,22 +115,20 @@ def generate_emotion(article):
|
|
| 102 |
|
| 103 |
def save_data_and_sendmail(article,output):
|
| 104 |
try:
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
# url = 'https://pragnakalpdev35.pythonanywhere.com/HF_space_que_gen'
|
| 109 |
# # url = 'http://pragnakalpdev33.pythonanywhere.com/HF_space_question_generator'
|
| 110 |
# myobj = {'article': article,'total_que': num_que,'gen_que':result,'ip_addr':hostname.get("ip_addr",""),'host':hostname.get("host","")}
|
| 111 |
# x = requests.post(url, json = myobj)
|
|
|
|
| 112 |
inputdata = article
|
| 113 |
-
ip = hostname.get("ip_addr","")
|
| 114 |
-
print(ip)
|
| 115 |
url = 'https://pragnakalpdev33.pythonanywhere.com/HF_space_bert_base_ner'
|
| 116 |
-
|
| 117 |
-
myobj = {'article': article,'gen_text':output,'ip_addr':hostname.get("ip_addr",""),'host':hostname.get("host","")}
|
| 118 |
x = requests.post(url, json = myobj)
|
| 119 |
|
| 120 |
-
add_csv = [inputdata,output,
|
| 121 |
with open(DATA_FILE, "a") as f:
|
| 122 |
writer = csv.writer(f)
|
| 123 |
# write the data
|
|
|
|
| 21 |
import socket
|
| 22 |
|
| 23 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 24 |
+
DATASET_NAME = "bert_based_ner_dataset "
|
| 25 |
DATASET_REPO_URL = f"https://huggingface.co/datasets/pragnakalp/{DATASET_NAME}"
|
| 26 |
DATA_FILENAME = "bert_base_ner_logs.csv"
|
| 27 |
DATA_FILE = os.path.join("bert_base_ner_logs", DATA_FILENAME)
|
|
|
|
| 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 |
print(result)
|
| 58 |
+
return ip_address
|
| 59 |
elif os.name == "posix":
|
| 60 |
gw = os.popen("ip -4 route show default").read().split()
|
| 61 |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
| 62 |
s.connect((gw[2], 0))
|
| 63 |
+
ip_address = s.getsockname()[0]
|
| 64 |
gateway = gw[2]
|
| 65 |
host = socket.gethostname()
|
|
|
|
|
|
|
| 66 |
print(result)
|
| 67 |
+
return ip_address
|
| 68 |
else:
|
| 69 |
result['id'] = os.name + " not supported yet."
|
| 70 |
print(result)
|
| 71 |
return result
|
| 72 |
|
| 73 |
+
def get_location(ip_addr):
|
| 74 |
+
ip=ip_addr
|
| 75 |
+
# ip=str(request.remote_addr)
|
| 76 |
+
req_data={
|
| 77 |
+
"ip":ip,
|
| 78 |
+
"token":"pkml123"
|
| 79 |
+
}
|
| 80 |
+
url = "https://demos.pragnakalp.com/get-ip-location"
|
| 81 |
|
| 82 |
+
# req_data=json.dumps(req_data)
|
| 83 |
+
# print("req_data",req_data)
|
| 84 |
+
headers = {'Content-Type': 'application/json'}
|
| 85 |
+
|
| 86 |
+
response = requests.request("POST", url, headers=headers, data=json.dumps(req_data))
|
| 87 |
+
response = response.json()
|
| 88 |
+
print("response======>>",response)
|
| 89 |
+
return response
|
| 90 |
+
|
| 91 |
def generate_emotion(article):
|
| 92 |
text = "Input sentence: "
|
| 93 |
text += article
|
|
|
|
| 115 |
|
| 116 |
def save_data_and_sendmail(article,output):
|
| 117 |
try:
|
| 118 |
+
ip_address = ''
|
| 119 |
+
ip_address = get_device_ip_address()
|
| 120 |
+
location = get_location(ip_address)
|
| 121 |
# url = 'https://pragnakalpdev35.pythonanywhere.com/HF_space_que_gen'
|
| 122 |
# # url = 'http://pragnakalpdev33.pythonanywhere.com/HF_space_question_generator'
|
| 123 |
# myobj = {'article': article,'total_que': num_que,'gen_que':result,'ip_addr':hostname.get("ip_addr",""),'host':hostname.get("host","")}
|
| 124 |
# x = requests.post(url, json = myobj)
|
| 125 |
+
|
| 126 |
inputdata = article
|
|
|
|
|
|
|
| 127 |
url = 'https://pragnakalpdev33.pythonanywhere.com/HF_space_bert_base_ner'
|
| 128 |
+
myobj = {'article': article,'gen_text':output,'ip_addr':ip_address,'loc':location}
|
|
|
|
| 129 |
x = requests.post(url, json = myobj)
|
| 130 |
|
| 131 |
+
add_csv = [inputdata,output,ip_address,location]
|
| 132 |
with open(DATA_FILE, "a") as f:
|
| 133 |
writer = csv.writer(f)
|
| 134 |
# write the data
|