Update main.py
Browse files
main.py
CHANGED
@@ -1,39 +1,15 @@
|
|
1 |
-
from flask import Flask, jsonify
|
2 |
-
import
|
3 |
-
import transformers
|
4 |
-
from huggingface_hub import cached_download
|
5 |
-
import torch
|
6 |
-
from torch import nn
|
7 |
-
import re
|
8 |
-
import numpy as np
|
9 |
-
import pandas as pd
|
10 |
-
from collections import OrderedDict
|
11 |
-
import os
|
12 |
-
# import requests
|
13 |
-
# from bs4 import BeautifulSoup
|
14 |
|
15 |
app = Flask(__name__)
|
16 |
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
# api_key = os.getenv('API_KEY')
|
22 |
-
# api_url = os.getenv('API_URL')
|
23 |
-
|
24 |
-
headers = {"Authorization": f"Bearer token"}
|
25 |
-
API_URL = "https://api-inference.huggingface.co/models/ProsusAI/finbert"
|
26 |
-
def query(payload):
|
27 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
28 |
-
return response.json()
|
29 |
-
|
30 |
-
|
31 |
-
@app.route("/", methods=["GET", "POST"])
|
32 |
-
def index():
|
33 |
-
user_input = None
|
34 |
-
response = None
|
35 |
-
if request.method == "POST":
|
36 |
-
user_input = request.form.get("user_input")
|
37 |
-
response = query({"inputs": user_input})
|
38 |
-
return render_template("home.html", user_input=user_input, response=response)
|
39 |
|
|
|
1 |
+
from flask import Flask, jsonify
|
2 |
+
import asyncio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
|
6 |
+
# Example async route using asyncio.sleep
|
7 |
+
@app.route('/async-task')
|
8 |
+
async def async_task():
|
9 |
+
await asyncio.sleep(2) # Simulate async task
|
10 |
+
return jsonify({"message": "Async task completed!"})
|
11 |
|
12 |
+
@app.route('/')
|
13 |
+
def home():
|
14 |
+
return jsonify({"message": "Welcome to my Flask API!"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|