Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,13 @@ from nltk.sentiment import SentimentIntensityAnalyzer
|
|
| 9 |
import nltk
|
| 10 |
from collections import Counter
|
| 11 |
import uvicorn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Download NLTK resources
|
| 14 |
try:
|
|
@@ -27,12 +34,12 @@ app.add_middleware(
|
|
| 27 |
allow_credentials=True,
|
| 28 |
allow_methods=["*"], # Allows all methods
|
| 29 |
allow_headers=["*"], # Allows all headers
|
| 30 |
-
)
|
| 31 |
|
| 32 |
humanize_pipe = None # Default to None before trying to load
|
| 33 |
|
| 34 |
try:
|
| 35 |
-
humanize_pipe = pipeline("text2text-generation", model="danibor/flan-t5-base-humanizer")
|
| 36 |
print("Humanization model loaded successfully!")
|
| 37 |
|
| 38 |
# Load spaCy model
|
|
@@ -74,12 +81,11 @@ async def humanize_text(request: TextRequest):
|
|
| 74 |
input_text = request.text
|
| 75 |
|
| 76 |
try:
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
raise HTTPException(status_code=500, detail="Humanization model is not loaded.")
|
| 80 |
|
| 81 |
-
|
| 82 |
-
humanized_text =
|
| 83 |
|
| 84 |
# Get the differences
|
| 85 |
diff = get_diff(input_text, humanized_text)
|
|
|
|
| 9 |
import nltk
|
| 10 |
from collections import Counter
|
| 11 |
import uvicorn
|
| 12 |
+
import requests
|
| 13 |
+
from dotenv import load_dotenv
|
| 14 |
+
import os
|
| 15 |
+
|
| 16 |
+
load_dotenv()
|
| 17 |
+
|
| 18 |
+
HF_API_TOKEN = os.getenv("HF_API_TOKEN")
|
| 19 |
|
| 20 |
# Download NLTK resources
|
| 21 |
try:
|
|
|
|
| 34 |
allow_credentials=True,
|
| 35 |
allow_methods=["*"], # Allows all methods
|
| 36 |
allow_headers=["*"], # Allows all headers
|
| 37 |
+
)
|
| 38 |
|
| 39 |
humanize_pipe = None # Default to None before trying to load
|
| 40 |
|
| 41 |
try:
|
| 42 |
+
# humanize_pipe = pipeline("text2text-generation", model="danibor/flan-t5-base-humanizer")
|
| 43 |
print("Humanization model loaded successfully!")
|
| 44 |
|
| 45 |
# Load spaCy model
|
|
|
|
| 81 |
input_text = request.text
|
| 82 |
|
| 83 |
try:
|
| 84 |
+
API_URL = "https://api-inference.huggingface.co/models/danibor/flan-t5-base-humanizer"
|
| 85 |
+
headers = {"Authorization": f"Bearer {HF_API_TOKEN}"}
|
|
|
|
| 86 |
|
| 87 |
+
response = requests.post(API_URL, headers=headers, json={"inputs": text})
|
| 88 |
+
humanized_text = response.json()[0]["generated_text"]
|
| 89 |
|
| 90 |
# Get the differences
|
| 91 |
diff = get_diff(input_text, humanized_text)
|