Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,73 +1,11 @@
|
|
| 1 |
-
from
|
| 2 |
-
from
|
| 3 |
-
from pydantic import BaseModel
|
| 4 |
-
from typing import Optional
|
| 5 |
-
import logging
|
| 6 |
-
from utils import *
|
| 7 |
|
| 8 |
-
app =
|
| 9 |
-
|
| 10 |
-
logger = logging.getLogger(__name__)
|
| 11 |
-
# Define the request model
|
| 12 |
-
class ArticleRequesteng(BaseModel):
|
| 13 |
-
article_title: str
|
| 14 |
-
main_keyword: str
|
| 15 |
-
target_tone: str
|
| 16 |
-
optional_text: str = None
|
| 17 |
-
# Define the request model
|
| 18 |
-
class ArticleRequest(BaseModel):
|
| 19 |
-
titre_article: str
|
| 20 |
-
mot_cle_principal: str
|
| 21 |
-
ton_cible: str
|
| 22 |
-
optional_text : str = None
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
async def generate_article(request: ArticleRequest):
|
| 30 |
-
"""
|
| 31 |
-
Endpoint to generate a French SEO article.
|
| 32 |
-
Parameters:
|
| 33 |
-
- titre_article: str - The title of the article.
|
| 34 |
-
- mot_cle_principal: str - The main keyword for the article.
|
| 35 |
-
- ton_cible: str - The target tone of the article.
|
| 36 |
-
- optional_text: str - Optional text to include in the article.
|
| 37 |
-
"""
|
| 38 |
-
try:
|
| 39 |
-
article = create_pipeline_fr(request.titre_article, request.mot_cle_principal, request.ton_cible,request.optional_text)
|
| 40 |
-
return ArticleResponse(article=article)
|
| 41 |
-
except Exception as e:
|
| 42 |
-
raise HTTPException(status_code=500, detail=str(e))
|
| 43 |
-
|
| 44 |
-
@app.post("/generate_article_eng", response_model=ArticleResponse)
|
| 45 |
-
async def generate_article_eng(request: ArticleRequesteng):
|
| 46 |
-
"""
|
| 47 |
-
Endpoint to generate an SEO article.
|
| 48 |
-
Parameters:
|
| 49 |
-
- article_title: str - The title of the article.
|
| 50 |
-
- main_keyword: str - The main keyword for the article.
|
| 51 |
-
- target_tone: str - The target tone of the article.
|
| 52 |
-
- optional_text: str - Optional text to include in the article.
|
| 53 |
-
"""
|
| 54 |
-
try:
|
| 55 |
-
# Basic validation of the input
|
| 56 |
-
if not request.article_title or not request.main_keyword:
|
| 57 |
-
raise HTTPException(status_code=400, detail="Title and main keyword are required")
|
| 58 |
-
|
| 59 |
-
article = create_pipeline(request.article_title, request.main_keyword, request.target_tone,request.optional_text)
|
| 60 |
-
|
| 61 |
-
# Ensure the response is not empty
|
| 62 |
-
if not article:
|
| 63 |
-
raise HTTPException(status_code=204, detail="Generated article is empty")
|
| 64 |
-
|
| 65 |
-
return ArticleResponse(article=article)
|
| 66 |
-
|
| 67 |
-
except HTTPException as http_exc:
|
| 68 |
-
logger.error(f"HTTP Exception: {http_exc.detail}")
|
| 69 |
-
raise http_exc
|
| 70 |
-
except Exception as e:
|
| 71 |
-
logger.error(f"Unhandled Exception: {str(e)}")
|
| 72 |
-
raise HTTPException(status_code=500, detail="An internal server error occurred")
|
| 73 |
-
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", return_all_scores=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
@app.route('/classify', methods=['POST'])
|
| 8 |
+
def classify():
|
| 9 |
+
text = request.json['text']
|
| 10 |
+
result = classifier(text)
|
| 11 |
+
return jsonify(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|