flaskapp / main.py
kumar9's picture
Update main.py
e2a16d4 verified
raw
history blame
1.04 kB
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)