Commit
·
1bff3b0
1
Parent(s):
03d5d72
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,36 +38,85 @@ repo = Repository(
|
|
| 38 |
local_dir="que_gen_logs", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
| 39 |
)
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
def generate_questions(article,num_que):
|
| 42 |
result = ''
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
-
return
|
| 71 |
|
| 72 |
## design 1
|
| 73 |
inputs=gr.Textbox(lines=5, label="Article/Text",elem_id="inp_div")
|
|
|
|
| 38 |
local_dir="que_gen_logs", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
| 39 |
)
|
| 40 |
|
| 41 |
+
def get_device_ip_address():
|
| 42 |
+
result = {}
|
| 43 |
+
if os.name == "nt":
|
| 44 |
+
result = "Running on Windows"
|
| 45 |
+
hostname = socket.gethostname()
|
| 46 |
+
ip_address = socket.gethostbyname(hostname)
|
| 47 |
+
result['ip_addr'] = ip_address
|
| 48 |
+
result['host'] = hostname
|
| 49 |
+
return result
|
| 50 |
+
elif os.name == "posix":
|
| 51 |
+
gw = os.popen("ip -4 route show default").read().split()
|
| 52 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
| 53 |
+
s.connect((gw[2], 0))
|
| 54 |
+
ipaddr = s.getsockname()[0]
|
| 55 |
+
gateway = gw[2]
|
| 56 |
+
host = socket.gethostname()
|
| 57 |
+
result['ip_addr'] = ipaddr
|
| 58 |
+
result['host'] = host
|
| 59 |
+
return result
|
| 60 |
+
else:
|
| 61 |
+
result = os.name + " not supported yet."
|
| 62 |
+
return result
|
| 63 |
+
|
| 64 |
def generate_questions(article,num_que):
|
| 65 |
result = ''
|
| 66 |
+
try:
|
| 67 |
+
if num_que == None or num_que == '':
|
| 68 |
+
num_que = 5
|
| 69 |
+
else:
|
| 70 |
+
num_que = num_que
|
| 71 |
+
generated_questions_list = qg.generate(article, num_questions=int(num_que))
|
| 72 |
+
summarized_data = {
|
| 73 |
+
"generated_questions" : generated_questions_list
|
| 74 |
+
}
|
| 75 |
+
generated_questions = summarized_data.get("generated_questions",'')
|
| 76 |
+
|
| 77 |
+
for q in generated_questions:
|
| 78 |
+
print(q)
|
| 79 |
+
result = result + q + '\n'
|
| 80 |
+
save_data_and_sendmail(article,generated_questions,num_que,result)
|
| 81 |
+
return result
|
| 82 |
+
except Exception as e:
|
| 83 |
+
return "Error while generating question -->" + e
|
| 84 |
+
"""
|
| 85 |
+
Save generated details
|
| 86 |
+
"""
|
| 87 |
+
def save_data_and_sendmail(article,generated_questions,num_que,result):
|
| 88 |
+
try:
|
| 89 |
+
article = ''
|
| 90 |
+
generated_questions = []
|
| 91 |
+
num_que = ''
|
| 92 |
+
result = ''
|
| 93 |
+
|
| 94 |
+
add_csv = [article, generated_questions, num_que]
|
| 95 |
+
with open(DATA_FILE, "a") as f:
|
| 96 |
+
writer = csv.writer(f)
|
| 97 |
+
# write the data
|
| 98 |
+
writer.writerow(add_csv)
|
| 99 |
+
commit_url = repo.push_to_hub()
|
| 100 |
+
print("commit data :",commit_url)
|
| 101 |
+
except Exception as e:
|
| 102 |
+
return "Error while storing data -->" + e
|
| 103 |
+
|
| 104 |
+
try:
|
| 105 |
+
hostname = get_device_ip_address()
|
| 106 |
+
url = 'http://pragnakalpdev35.pythonanywhere.com/HF_space_que_gen'
|
| 107 |
+
myobj = {'article': article,'gen_que':result,'ip_addr':hostname.get("ip_addr",""),'host':hostname.get("host","")}
|
| 108 |
+
x = requests.post(url, json = myobj)
|
| 109 |
+
print(x)
|
| 110 |
+
# with open(DATA_FILE, "r") as file:
|
| 111 |
+
# data = json.load(file)
|
| 112 |
+
# data.append(entry)
|
| 113 |
+
# with open(DATA_FILE, "w") as file:
|
| 114 |
+
# json.dump(data, file)
|
| 115 |
+
# commit_url = repo.push_to_hub()
|
| 116 |
+
except Exception as e:
|
| 117 |
+
return "Error while sending mail"
|
| 118 |
|
| 119 |
+
return "Successfully save data"
|
| 120 |
|
| 121 |
## design 1
|
| 122 |
inputs=gr.Textbox(lines=5, label="Article/Text",elem_id="inp_div")
|