Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,12 @@
|
|
1 |
from fastapi import FastAPI, UploadFile, File
|
2 |
import requests
|
3 |
-
import os
|
4 |
|
5 |
app = FastAPI()
|
6 |
|
7 |
-
# URL de l’API Ollama (
|
8 |
OLLAMA_API_URL = "http://localhost:11434/api/generate"
|
9 |
|
10 |
-
# Fonction pour
|
11 |
def query_ollama(prompt: str, model: str = "mistral"):
|
12 |
payload = {
|
13 |
"model": model,
|
@@ -22,26 +21,13 @@ def query_ollama(prompt: str, model: str = "mistral"):
|
|
22 |
|
23 |
@app.get("/")
|
24 |
async def root():
|
25 |
-
return {"message": "
|
26 |
|
27 |
-
#
|
28 |
@app.post("/summarization/text")
|
29 |
async def summarize_text(file: UploadFile = File(...)):
|
30 |
-
# Lire le contenu du fichier uploadé
|
31 |
content = await file.read()
|
32 |
text = content.decode("utf-8")
|
33 |
-
|
34 |
-
# Créer un prompt pour Ollama
|
35 |
prompt = f"Résume ce texte en 3 phrases courtes : {text}"
|
36 |
-
|
37 |
-
# Appeler Ollama avec le modèle (Mistral ou DeepSeek si disponible)
|
38 |
-
summary = query_ollama(prompt, model="mistral") # Remplace "mistral" par "deepseek-v2" si tu l’as
|
39 |
-
|
40 |
-
return {"summary": summary}
|
41 |
-
|
42 |
-
# Exemple d’endpoint pour tester avec du texte brut
|
43 |
-
@app.post("/summarization/test")
|
44 |
-
async def summarize_test(text: str):
|
45 |
-
prompt = f"Résume ce texte en 3 phrases courtes : {text}"
|
46 |
-
summary = query_ollama(prompt, model="mistral")
|
47 |
return {"summary": summary}
|
|
|
1 |
from fastapi import FastAPI, UploadFile, File
|
2 |
import requests
|
|
|
3 |
|
4 |
app = FastAPI()
|
5 |
|
6 |
+
# URL de l’API Ollama (local dans le conteneur)
|
7 |
OLLAMA_API_URL = "http://localhost:11434/api/generate"
|
8 |
|
9 |
+
# Fonction pour interroger Ollama
|
10 |
def query_ollama(prompt: str, model: str = "mistral"):
|
11 |
payload = {
|
12 |
"model": model,
|
|
|
21 |
|
22 |
@app.get("/")
|
23 |
async def root():
|
24 |
+
return {"message": "API avec Ollama sur Hugging Face Spaces"}
|
25 |
|
26 |
+
# Exemple d’endpoint pour résumer un texte
|
27 |
@app.post("/summarization/text")
|
28 |
async def summarize_text(file: UploadFile = File(...)):
|
|
|
29 |
content = await file.read()
|
30 |
text = content.decode("utf-8")
|
|
|
|
|
31 |
prompt = f"Résume ce texte en 3 phrases courtes : {text}"
|
32 |
+
summary = query_ollama(prompt, model="mistral") # Remplace par "deepseek-v2" si dispo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
return {"summary": summary}
|