Spaces:
Running
Running
Commit ·
321d5fe
1
Parent(s): 1f4a0b6
Fix issue with app.py
Browse files- backend/app.py +1 -7
backend/app.py
CHANGED
|
@@ -6,10 +6,6 @@ from fastapi.responses import FileResponse
|
|
| 6 |
from transformers import GPT2Tokenizer, GPT2Model, pipeline
|
| 7 |
import torch as t
|
| 8 |
import logging
|
| 9 |
-
import pydantic
|
| 10 |
-
from pydantic import BaseModel
|
| 11 |
-
class TextRequest(BaseModel):
|
| 12 |
-
text: str
|
| 13 |
|
| 14 |
logging.basicConfig(level=logging.INFO)
|
| 15 |
logger = logging.getLogger(__name__)
|
|
@@ -38,15 +34,13 @@ except Exception as e:
|
|
| 38 |
raise
|
| 39 |
|
| 40 |
@app.post("/process")
|
| 41 |
-
async def process_text(
|
| 42 |
"""
|
| 43 |
Process the input text:
|
| 44 |
- Tokenizes the text
|
| 45 |
- Runs the GPT2 model to obtain attentions
|
| 46 |
- Returns the tokens and attention values (rounded to 2 decimals)
|
| 47 |
"""
|
| 48 |
-
|
| 49 |
-
text = payload.txt
|
| 50 |
try:
|
| 51 |
logger.info(f"Received text: {text}")
|
| 52 |
# Tokenize input text (truncating if needed)
|
|
|
|
| 6 |
from transformers import GPT2Tokenizer, GPT2Model, pipeline
|
| 7 |
import torch as t
|
| 8 |
import logging
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
logging.basicConfig(level=logging.INFO)
|
| 11 |
logger = logging.getLogger(__name__)
|
|
|
|
| 34 |
raise
|
| 35 |
|
| 36 |
@app.post("/process")
|
| 37 |
+
async def process_text(text: str = Body(..., embed=True)):
|
| 38 |
"""
|
| 39 |
Process the input text:
|
| 40 |
- Tokenizes the text
|
| 41 |
- Runs the GPT2 model to obtain attentions
|
| 42 |
- Returns the tokens and attention values (rounded to 2 decimals)
|
| 43 |
"""
|
|
|
|
|
|
|
| 44 |
try:
|
| 45 |
logger.info(f"Received text: {text}")
|
| 46 |
# Tokenize input text (truncating if needed)
|