File size: 832 Bytes
2c42053
0307266
 
28fba93
0307266
 
2c42053
 
0307266
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2c42053
 
 
0307266
 
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
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import os
import requests

HF_TOKEN = os.environ.get('HF_TOKEN')

app = FastAPI(title="Deploying FastAPI Apps on Huggingface")
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)


API_URL = "https://api-inference.huggingface.co/models/google/gemma-1.1-7b-it"
headers = {"Authorization": f"Bearer {HF_TOKEN}"}

def query(payload):
	response = requests.post(API_URL, headers=headers, json=payload)
	return response.json()

@app.get("/query", tags=["Query"])
def api_query(input: str):
    return query({"inputs": input,"parameters":{"return_full_text":False,"max_length":1024}})

@app.get("/", tags=["Home"])
def api_home():
    return {'message': 'Welcome!'}