Commit
·
bbd4ef9
1
Parent(s):
3e63657
Update app.py
Browse files
app.py
CHANGED
@@ -39,7 +39,7 @@ repo = Repository(
|
|
39 |
local_dir="que_gen_logs", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
40 |
)
|
41 |
|
42 |
-
def
|
43 |
result = {}
|
44 |
if os.name == "nt":
|
45 |
result = "Running on Windows"
|
@@ -90,43 +90,12 @@ Save generated details
|
|
90 |
"""
|
91 |
def save_data_and_sendmail(article,generated_questions,num_que,result):
|
92 |
try:
|
93 |
-
|
94 |
-
|
95 |
-
generated_questions1 = []
|
96 |
-
generated_questions1 = generated_questions
|
97 |
-
num_que1 = num_que
|
98 |
-
result1 = result
|
99 |
-
result2 = {}
|
100 |
-
print("********",article1,generated_questions1,num_que1,result1)
|
101 |
-
# hostname = get_device_ip_address()
|
102 |
-
if os.name == "nt":
|
103 |
-
result = "Running on Windows"
|
104 |
-
hostname = socket.gethostname()
|
105 |
-
ip_address = socket.gethostbyname(hostname)
|
106 |
-
result2['ip_addr'] = ip_address
|
107 |
-
result2['host'] = hostname
|
108 |
-
print(result2)
|
109 |
-
elif os.name == "posix":
|
110 |
-
gw = os.popen("ip -4 route show default").read().split()
|
111 |
-
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
112 |
-
s.connect((gw[2], 0))
|
113 |
-
ipaddr = s.getsockname()[0]
|
114 |
-
gateway = gw[2]
|
115 |
-
host = socket.gethostname()
|
116 |
-
result2['ip_addr'] = ipaddr
|
117 |
-
result2['host'] = host
|
118 |
-
print(result2)
|
119 |
-
else:
|
120 |
-
result2['id'] = os.name + " not supported yet."
|
121 |
-
print(result2)
|
122 |
-
hostname = result2
|
123 |
-
print(hostname)
|
124 |
url = 'https://pragnakalpdev35.pythonanywhere.com/HF_space_que_gen'
|
125 |
# url = 'http://pragnakalpdev33.pythonanywhere.com/HF_space_question_generator'
|
126 |
-
myobj = {'article':
|
127 |
-
|
128 |
-
x = requests.post(url, json = myobj)
|
129 |
-
print(x)
|
130 |
add_csv = [article, generated_questions, num_que]
|
131 |
with open(DATA_FILE, "a") as f:
|
132 |
writer = csv.writer(f)
|
@@ -138,7 +107,6 @@ def save_data_and_sendmail(article,generated_questions,num_que,result):
|
|
138 |
# return "Error while storing data -->" + e
|
139 |
|
140 |
# try:
|
141 |
-
|
142 |
# with open(DATA_FILE, "r") as file:
|
143 |
# data = json.load(file)
|
144 |
# data.append(entry)
|
@@ -146,7 +114,7 @@ def save_data_and_sendmail(article,generated_questions,num_que,result):
|
|
146 |
# json.dump(data, file)
|
147 |
# commit_url = repo.push_to_hub()
|
148 |
except Exception as e:
|
149 |
-
return "Error while sending mail"
|
150 |
|
151 |
return "Successfully save data"
|
152 |
|
|
|
39 |
local_dir="que_gen_logs", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
40 |
)
|
41 |
|
42 |
+
def get_device_ip_address():
|
43 |
result = {}
|
44 |
if os.name == "nt":
|
45 |
result = "Running on Windows"
|
|
|
90 |
"""
|
91 |
def save_data_and_sendmail(article,generated_questions,num_que,result):
|
92 |
try:
|
93 |
+
hostname = {}
|
94 |
+
hostname = get_device_ip_address()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
url = 'https://pragnakalpdev35.pythonanywhere.com/HF_space_que_gen'
|
96 |
# url = 'http://pragnakalpdev33.pythonanywhere.com/HF_space_question_generator'
|
97 |
+
myobj = {'article': article,'gen_que':result,'ip_addr':hostname.get("ip_addr",""),'host':hostname.get("host","")}
|
98 |
+
x = requests.post(url, json = myobj)
|
|
|
|
|
99 |
add_csv = [article, generated_questions, num_que]
|
100 |
with open(DATA_FILE, "a") as f:
|
101 |
writer = csv.writer(f)
|
|
|
107 |
# return "Error while storing data -->" + e
|
108 |
|
109 |
# try:
|
|
|
110 |
# with open(DATA_FILE, "r") as file:
|
111 |
# data = json.load(file)
|
112 |
# data.append(entry)
|
|
|
114 |
# json.dump(data, file)
|
115 |
# commit_url = repo.push_to_hub()
|
116 |
except Exception as e:
|
117 |
+
return "Error while sending mail" + e
|
118 |
|
119 |
return "Successfully save data"
|
120 |
|