File size: 622 Bytes
61a85fa
 
 
a209feb
be272da
a209feb
61a85fa
 
4ab117d
4fa3775
 
61a85fa
51450a7
be272da
f4f9df5
a209feb
be272da
 
f4f9df5
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from typing import Union
from fastapi import FastAPI
from huggingface_hub import InferenceClient
import os 
import json

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello World"}

@app.post("/chat")
async def chat(message: dict):
    try:
        client = InferenceClient(model="gpt2", token=os.environ.get(api_key))
        input_text = message
        response = client.text_generation(input_text)
        print(response)
        return {"message": response}
    except Exception as e:
        print(f"Error: {e}")
        raise HTTPException(status_code=500, detail="Internal server error")