-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
70 lines (57 loc) · 1.59 KB
/
demo.py
File metadata and controls
70 lines (57 loc) · 1.59 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
from typing import Union
from fastapi import FastAPI
from huggingface_hub import InferenceClient
from datetime import datetime
from dotenv import load_dotenv
load_dotenv()
# client = InferenceClient(model="HuggingFaceTB/SmolLM-135M", token=os.getenv('HFTOKEN'))
client = InferenceClient(model="gpt2", token=os.getenv('HFTOKEN'))
app = FastAPI()
# print(app)
@app.get("/")
async def root():
return {"message":"hello thanga"}
@app.get("/hello/")
async def root():
time = datetime.now()
return {"message":"Once again a hello",
"time is": time}
@app.get("/time")
async def time():
time = datetime.now()
return {
"hey" : "hello, welcome again",
"time is" : time
}
@app.get("/get_token")
async def token():
token = os.getenv('HFTOKEN')
print(token)
return {
"token - ": token
}
# lets say to get the cli / client details
@app.get("/cli/details/")
async def details():
return {
"Client Info -": client
}
# generate default text with given prompt
@app.get("/generate")
async def gen(prompt):
prompt = "India is a country known for its spices and"
response = client.text_generation(prompt)
return {
"prompt" : prompt,
"response" : response
}
@app.get("/converse")
async def converse(prompt : Union[str,None]): # type annotations
# Union tells this or that (string or empty)
prompt = prompt or "Indian is known for"
response = client.text_generation(prompt)
return {
"prompt" : prompt,
"response" : response
}