Spaces:
Runtime error
Runtime error
File size: 975 Bytes
dde26ac 420d681 3e26431 420d681 3e26431 bb2c44a dde26ac 0e3f8e5 dde26ac |
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 |
import logging
from sklearn.linear_model import SGDClassifier
import uvicorn
from fastapi import FastAPI
app = FastAPI()
def predict(input_text: str):
data = [[ord(c) for c in input_text]] # Convert the string to a list of ASCII values
model = train(data)
# Make a prediction
prediction = model.predict([[ord(c) for c in 'abc']]) # Convert the input string to a list of ASCII values
return {"prediction": prediction}
def train(X):
model = SGDClassifier()
model.fit(X, X) # In this case, we are using the input data as the labels
return model
# Here you can do things such as load your models
@app.get("/")
def read_root(input_text):
logging.info("Received request with input_text: %s", input_text)
try:
result = predict(input_text)
logging.info("Prediction made: %s", result)
return {"result": 1}
except Exception as e:
logging.error("An error occured: %s", e)
return {"error": str(e)} |