Spaces:
Runtime error
Runtime error
Update TextGen/router.py
Browse files- TextGen/router.py +0 -34
TextGen/router.py
CHANGED
@@ -3,39 +3,9 @@ from pydantic import BaseModel
|
|
3 |
from .ConfigEnv import config
|
4 |
from fastapi.middleware.cors import CORSMiddleware
|
5 |
|
6 |
-
from langchain.llms import Clarifai
|
7 |
-
from langchain.chains import LLMChain
|
8 |
-
from langchain.prompts import PromptTemplate
|
9 |
|
10 |
from TextGen import app
|
11 |
|
12 |
-
class Generate(BaseModel):
|
13 |
-
text:str
|
14 |
-
|
15 |
-
def generate_text(prompt: str):
|
16 |
-
if prompt == "":
|
17 |
-
return {"detail": "Please provide a prompt."}
|
18 |
-
else:
|
19 |
-
prompt = PromptTemplate(template=prompt, input_variables=['Prompt'])
|
20 |
-
|
21 |
-
llm = Clarifai(
|
22 |
-
pat = config.CLARIFAI_PAT,
|
23 |
-
user_id = config.USER_ID,
|
24 |
-
app_id = config.APP_ID,
|
25 |
-
model_id = config.MODEL_ID,
|
26 |
-
model_version_id=config.MODEL_VERSION_ID,
|
27 |
-
)
|
28 |
-
|
29 |
-
llmchain = LLMChain(
|
30 |
-
prompt=prompt,
|
31 |
-
llm=llm
|
32 |
-
)
|
33 |
-
|
34 |
-
llm_response = llmchain.run({"Prompt": prompt})
|
35 |
-
return Generate(text=llm_response)
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
app.add_middleware(
|
40 |
CORSMiddleware,
|
41 |
allow_origins=["*"],
|
@@ -47,7 +17,3 @@ app.add_middleware(
|
|
47 |
@app.get("/", tags=["Home"])
|
48 |
def api_home():
|
49 |
return {'detail': 'Welcome to FastAPI TextGen Tutorial!'}
|
50 |
-
|
51 |
-
@app.post("/api/generate", summary="Generate text from prompt", tags=["Generate"], response_model=Generate)
|
52 |
-
def inference(input_prompt: str):
|
53 |
-
return "hi"
|
|
|
3 |
from .ConfigEnv import config
|
4 |
from fastapi.middleware.cors import CORSMiddleware
|
5 |
|
|
|
|
|
|
|
6 |
|
7 |
from TextGen import app
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
app.add_middleware(
|
10 |
CORSMiddleware,
|
11 |
allow_origins=["*"],
|
|
|
17 |
@app.get("/", tags=["Home"])
|
18 |
def api_home():
|
19 |
return {'detail': 'Welcome to FastAPI TextGen Tutorial!'}
|
|
|
|
|
|
|
|