File size: 1,037 Bytes
9d9c274
e909703
9abed3a
18f5113
43dcf13
 
e085476
14f5c56
 
 
a793420
24668a8
 
4393529
 
 
18f5113
6013fef
f0224cb
a793420
557b429
 
5d683ae
e2a16d4
557b429
e909703
557b429
e909703
9abed3a
 
bf01bb4
 
 
 
 
 
 
d6af0b7
bf01bb4
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
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
# import requests
# from bs4 import BeautifulSoup

app = Flask(__name__)



os.environ['TRANSFORMERS_CACHE'] = '/.cache/huggingface/hub'

# api_key = os.getenv('API_KEY')
# api_url = os.getenv('API_URL')

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)