Spaces:
Runtime error
Runtime error
| 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!D"+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() |