|
from flask import Flask, jsonify, render_template, request, make_response |
|
import requests |
|
import transformers |
|
from huggingface_hub import cached_download |
|
import torch |
|
from torch import nn |
|
import re |
|
import numpy as np |
|
import pandas as pd |
|
from collections import OrderedDict |
|
import os |
|
|
|
|
|
|
|
app = Flask(__name__) |
|
|
|
|
|
|
|
os.environ['TRANSFORMERS_CACHE'] = '/.cache/huggingface/hub' |
|
|
|
|
|
|
|
|
|
headers = {"Authorization": f"Bearer token"} |
|
API_URL = "https://api-inference.huggingface.co/models/ProsusAI/finbert" |
|
def query(payload): |
|
response = requests.post(API_URL, headers=headers, json=payload) |
|
return response.json() |
|
|
|
|
|
@app.route("/", methods=["GET", "POST"]) |
|
def index(): |
|
user_input = None |
|
response = None |
|
if request.method == "POST": |
|
user_input = request.form.get("user_input") |
|
response = query({"inputs": user_input}) |
|
return render_template("home.html", user_input=user_input, response=response) |
|
|
|
|