Fric7ion commited on
Commit
61a85fa
1 Parent(s): 3c22d19

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +23 -0
main.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Union
2
+
3
+ from fastapi import FastAPI
4
+
5
+ from huggingface_hub import InferenceClient
6
+
7
+ app = FastAPI()
8
+
9
+ @app.get("/")
10
+ async def root():
11
+ return {"message": "Hello World"}
12
+
13
+ @app.get("/chat")
14
+ async def chat(prompt: Union[str, None] = None, max_token: Union[str, None] = None):
15
+ client = InferenceClient(model="gpt2", token=api_key)
16
+ input_text = prompt or "Once upon a time"
17
+
18
+ # Call the text generation API
19
+ response = client.text_generation(input_text, max_new_tokens=int(max_token or "140"))
20
+
21
+ # Print the generated text
22
+ print(response)
23
+ return {"message": response}