5m4ck3r commited on
Commit
d6f16db
·
verified ·
1 Parent(s): e2a16d4

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +10 -34
main.py CHANGED
@@ -1,39 +1,15 @@
1
- from flask import Flask, jsonify, render_template, request, make_response
2
- import requests
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
- os.environ['TRANSFORMERS_CACHE'] = '/.cache/huggingface/hub'
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