Spaces:
Sleeping
Sleeping
Create main.p
Browse files
main.p
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
client = InferenceClient(
|
| 8 |
+
model="VoltIC/Automated-Text-Summarizer",
|
| 9 |
+
token=os.getenv("HF_TOKEN")
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
@app.get("/")
|
| 13 |
+
def home():
|
| 14 |
+
return {"message": "Summarizer API is running!"}
|
| 15 |
+
|
| 16 |
+
@app.post("/summarize")
|
| 17 |
+
def summarize(text: str):
|
| 18 |
+
try:
|
| 19 |
+
summary = client.summarization(text)
|
| 20 |
+
return {"summary": summary}
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return {"error": str(e)}
|