File size: 2,343 Bytes
fc6f922
 
bde3f08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cf907ed
bde3f08
 
 
 
 
 
 
63c29f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99ce06d
 
63c29f1
 
 
 
 
99ce06d
 
 
 
 
 
 
 
 
 
 
103fbec
99ce06d
 
 
63c29f1
bde3f08
 
 
 
 
 
fc6f922
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
71
72
import gradio as gr

import tensorflow as tf
import numpy as np
import pickle

# Load model, including its weights and the optimizer
model = tf.keras.models.load_model('core4.h5')

# load tokenizer
with open('tokenizer.pickle', 'rb') as handle:
    tokenize = pickle.load(handle)

text_labels = ['How to apply', 'how much can I get', 'who can apply']

# model.summary() # model architecture

def greet(string):

  tokenizedText = tokenize.texts_to_matrix([string])
  prediction = model.predict(np.array([tokenizedText[0]]))
  predicted_label = text_labels[np.argmax(prediction)]

  print(prediction[0][np.argmax(prediction)])
  print("Predicted label: " + predicted_label + "\n")
  
  ###################
  import requests as rs
  import pandas as pd
  
  spreadsheet_id = '1vjWnYsnGc0J6snT67NVbA-NWSGZ5b0eDBVHmg9lbf9s'  # Please set the Spreadsheet ID.
  csv_url='https://docs.google.com/spreadsheets/d/' + spreadsheet_id + '/export?format=csv&id=' + spreadsheet_id + '&gid=0'
  
  res=rs.get(url=csv_url)
  open('google.csv', 'wb').write(res.content)
  df = pd.read_csv('google.csv')
  
  import json
  import requests
  
  spreadsheet_id = '1vjWnYsnGc0J6snT67NVbA-NWSGZ5b0eDBVHmg9lbf9s'  # Please set the Spreadsheet ID.  
  url = 'https://script.google.com/macros/s/AKfycbwXP5fsDgOXJ9biZQC293o6bTBL3kDOJ07PlmxKjabzdTej6WYdC8Yos6NpDVqAJeVM/exec?spreadsheetId=' + spreadsheet_id
  body = {
      "arguments": {"range": "Sheet1!A"+str(len(df)+2), "valueInputOption": "USER_ENTERED"},
      "body": {"values": [[string]]}
  }
  res = requests.post(url, json.dumps(body), headers={'Content-Type': 'application/json'})
  
  body = {
      "arguments": {"range": "Sheet1!B"+str(len(df)+2), "valueInputOption": "USER_ENTERED"},
      "body": {"values": [[predicted_label]]}
  }
  res = requests.post(url, json.dumps(body), headers={'Content-Type': 'application/json'})
  
  import datetime
  current_time = datetime.datetime.now()
  body = {
      "arguments": {"range": "Sheet1!C"+str(len(df)+2), "valueInputOption": "USER_ENTERED"},
      "body": {"values": [[str(current_time)]]}
  }
  res = requests.post(url, json.dumps(body), headers={'Content-Type': 'application/json'})
  #print(res.text)
  #######################

  return predicted_label


#One testing case


iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()