Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,34 +1,16 @@
|
|
| 1 |
-
|
| 2 |
|
| 3 |
-
from .ConfigEnv import config
|
| 4 |
from fastapi.middleware.cors import CORSMiddleware
|
| 5 |
|
| 6 |
-
from
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
if prompt == "":
|
| 16 |
-
return {"detail": "Please provide a prompt."}
|
| 17 |
-
else:
|
| 18 |
-
prompt = PromptTemplate(template=prompt, input_variables=['Prompt'])
|
| 19 |
-
llm = Clarifai(
|
| 20 |
-
pat = config.CLARIFAI_PAT,
|
| 21 |
-
user_id = config.USER_ID,
|
| 22 |
-
app_id = config.APP_ID,
|
| 23 |
-
model_id = config.MODEL_ID,
|
| 24 |
-
model_version_id=config.MODEL_VERSION_ID,
|
| 25 |
-
)
|
| 26 |
-
llmchain = LLMChain(
|
| 27 |
-
prompt=prompt,
|
| 28 |
-
llm=llm
|
| 29 |
-
)
|
| 30 |
-
llm_response = llmchain.run({"Prompt": prompt})
|
| 31 |
-
return Generate(text=llm_response)
|
| 32 |
|
| 33 |
app.add_middleware(
|
| 34 |
CORSMiddleware,
|
|
@@ -37,11 +19,12 @@ app.add_middleware(
|
|
| 37 |
allow_methods=["*"],
|
| 38 |
allow_headers=["*"],
|
| 39 |
)
|
|
|
|
| 40 |
|
| 41 |
@app.get("/", tags=["Home"])
|
| 42 |
def api_home():
|
| 43 |
return {'detail': 'Welcome to FastAPI TextGen Tutorial!'}
|
| 44 |
|
| 45 |
-
@app.
|
| 46 |
-
def inference(
|
| 47 |
-
return
|
|
|
|
| 1 |
+
import requests
|
| 2 |
|
|
|
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
|
| 5 |
+
from fastapi import FastAPI
|
| 6 |
+
|
| 7 |
+
API_URL = "https://api-inference.huggingface.co/models/google/gemma-1.1-7b-it"
|
| 8 |
+
|
| 9 |
+
def query(payload):
|
| 10 |
+
response = requests.post(API_URL, json=payload)
|
| 11 |
+
return response.json()
|
| 12 |
+
|
| 13 |
+
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
app.add_middleware(
|
| 16 |
CORSMiddleware,
|
|
|
|
| 19 |
allow_methods=["*"],
|
| 20 |
allow_headers=["*"],
|
| 21 |
)
|
| 22 |
+
|
| 23 |
|
| 24 |
@app.get("/", tags=["Home"])
|
| 25 |
def api_home():
|
| 26 |
return {'detail': 'Welcome to FastAPI TextGen Tutorial!'}
|
| 27 |
|
| 28 |
+
@app.get("/api/generate", summary="Generate text from prompt", tags=["Generate"])
|
| 29 |
+
def inference(input: str):
|
| 30 |
+
return query({"inputs": input})
|