usag1e commited on
Commit
a931f78
·
1 Parent(s): 5d91af1

Fix: Parse input_text from request body

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -1,20 +1,19 @@
1
  from fastapi import FastAPI, HTTPException
2
- from huggingface_hub import InferenceClient
3
 
4
  app = FastAPI()
5
 
6
- # Initialize the Hugging Face client
7
- client = InferenceClient(model="HuggingFaceH4/zephyr-7b-beta")
 
8
 
9
  @app.get("/")
10
  def root():
11
  return {"message": "Welcome to the LLM API"}
12
 
13
  @app.post("/predict")
14
- def predict(input_text: str):
15
- try:
16
- # Make a prediction using the Hugging Face model
17
- response = client.text_generation(input_text)
18
- return {"response": response}
19
- except Exception as e:
20
- raise HTTPException(status_code=500, detail=str(e))
 
1
  from fastapi import FastAPI, HTTPException
2
+ from pydantic import BaseModel
3
 
4
  app = FastAPI()
5
 
6
+ # Define the input schema
7
+ class InputText(BaseModel):
8
+ input_text: str
9
 
10
  @app.get("/")
11
  def root():
12
  return {"message": "Welcome to the LLM API"}
13
 
14
  @app.post("/predict")
15
+ def predict(data: InputText):
16
+ # Access the input_text from the request body
17
+ input_text = data.input_text
18
+ # For now, return the input text as a response
19
+ return {"response": f"The input was: {input_text}"}