Skip to content

Commit fb0f709

Browse files
authored
Merge pull request #8 from SalimM21/SALIM
Salim
2 parents 01ff392 + 9db9e55 commit fb0f709

11 files changed

Lines changed: 113 additions & 24 deletions

File tree

.gradio/certificate.pem

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
3+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
4+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
5+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
6+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
7+
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
8+
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
9+
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
10+
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
11+
T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH
12+
B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC
13+
B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv
14+
KBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9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Bs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
31+
-----END CERTIFICATE-----

Docker-SA

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 080f7ab5c61d7c04e8a43faf7f405a619385bbc4

Dockerfile

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1-
FROM python:3.11-slim
1+
FROM python:3.10-slim
22

3-
ENV PYTHONDONTWRITEBYTECODE=1 \
4-
PYTHONUNBUFFERED=1
3+
# Installer dépendances système nécessaires pour torch et transformers
4+
RUN apt-get update && apt-get install -y \
5+
build-essential \
6+
curl \
7+
git \
8+
&& rm -rf /var/lib/apt/lists/*
59

610
WORKDIR /app
711

12+
# Copier le fichier requirements.txt
813
COPY requirements.txt .
14+
15+
# Upgrade pip
16+
RUN pip install --upgrade pip
17+
18+
# Installer les dépendances Python, incluant torch CPU
19+
RUN pip install --no-cache-dir torch==2.2.0 -f https://download.pytorch.org/whl/cpu/torch_stable.html
20+
RUN pip install --no-cache-dir "numpy<2"
921
RUN pip install --no-cache-dir -r requirements.txt
1022

11-
COPY app ./app
12-
COPY static ./static
23+
# Copier le reste du projet
24+
COPY . .
1325

26+
# Exposer le port 7860 (obligatoire pour HF Spaces)
1427
EXPOSE 7860
15-
# Hugging Face Spaces fournit $PORT
16-
CMD uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-7860}
28+
29+
# Lancer FastAPI via Uvicorn (forme JSON recommandée)
30+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]

Gradio

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 85120273af3c2585ca91c77d51d0595d17309d8b

__pycache__/main.cpython-312.pyc

5.34 KB
Binary file not shown.

app.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import gradio as gr
2+
from transformers import pipeline
3+
import os
4+
5+
# Charger le modèle (identique à celui de ton API)
6+
MODEL_NAME = os.getenv("HF_MODEL", "distilbert-base-uncased-finetuned-sst-2-english")
7+
sentiment_pipe = pipeline("sentiment-analysis", model=MODEL_NAME)
8+
9+
# Fonction de prédiction
10+
def predict_sentiment(text):
11+
result = sentiment_pipe(text)[0]
12+
label = "positive" if result["label"].upper().startswith("POS") else "negative"
13+
confidence = float(result["score"])
14+
return f"Label: {label}, Confidence: {confidence:.4f}"
15+
16+
# Interface Gradio
17+
iface = gr.Interface(
18+
fn=predict_sentiment,
19+
inputs=gr.Textbox(lines=3, placeholder="Entrez votre texte ici..."),
20+
outputs="text",
21+
title="Sentiment Analysis Demo",
22+
description=f"Modèle: {MODEL_NAME}"
23+
)
24+
25+
# Lancer l'interface en local
26+
if __name__ == "__main__":
27+
iface.launch(share=True)
28+
14 Bytes
Binary file not shown.

app/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
)
4141

4242
# Serve static files (page HTML de test)
43-
STATIC_DIR = os.path.join(os.path.dirname(__file__), "..", "static")
43+
STATIC_DIR = os.path.join(os.path.dirname(__file__), "../static")
4444
app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
4545

4646
@app.get("/", include_in_schema=False)

requirements.txt

-8.13 KB
Binary file not shown.

static/index.html

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
11
<!doctype html>
22
<html lang="fr">
3+
34
<head>
45
<meta charset="utf-8" />
56
<meta name="viewport" content="width=device-width, initial-scale=1" />
67
<title>Test Sentiment API</title>
7-
<style>
8-
body { font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; margin: 2rem; max-width: 800px; }
9-
textarea { width: 100%; min-height: 120px; }
10-
button { padding: .6rem 1rem; cursor: pointer; }
11-
.result { margin-top: 1rem; padding: 1rem; border: 1px solid #ddd; border-radius: .5rem; white-space: pre-wrap; }
12-
code { background: #f7f7f7; padding: .2rem .4rem; border-radius: .3rem; }
13-
</style>
8+
<!-- Tailwind CSS CDN -->
9+
<script src="https://cdn.tailwindcss.com"></script>
1410
</head>
15-
<body>
16-
<h1>Test de l'API d'analyse de sentiments</h1>
17-
<p>
18-
Tapez un texte et cliquez sur <b>Analyser</b>. L'API appelle <code>POST /predict</code> et affiche le JSON de réponse.
19-
</p>
2011

21-
<textarea id="text" placeholder="I love this product!"></textarea><br><br>
22-
<button id="btn">Analyser</button>
23-
<div class="result" id="result">Résultat…</div>
12+
<body class="bg-gray-100 min-h-screen flex items-center justify-center">
13+
<div class="max-w-2xl w-full bg-white shadow-md rounded-2xl p-8">
14+
<h1 class="text-2xl font-bold mb-4">Test de l'API pour l'analyse des sentiments</h1>
15+
<p class="text-gray-700 mb-6">
16+
Tapez un texte et cliquez sur <b>Analyser</b>.
17+
<!-- L'API appelle <code class="bg-gray-100 px-1 py-0.5 rounded">POST /predict</code> et affiche le JSON de réponse. -->
18+
</p>
19+
20+
<div class="mb-4">
21+
<label for="text" class="block font-medium text-gray-800 mb-2">Votre texte</label>
22+
<textarea id="text" rows="4" placeholder="I love this product!"
23+
class="w-full border border-gray-300 rounded-lg p-3 focus:outline-none focus:ring-2 focus:ring-blue-500"></textarea>
24+
</div>
25+
26+
<button id="btn" class="bg-blue-600 text-white px-5 py-2 rounded-lg hover:bg-blue-700 transition">
27+
Analyser
28+
</button>
29+
30+
<div class="mt-6">
31+
<h5 class="text-lg font-semibold">Résultat</h5>
32+
<pre id="result"
33+
class="mt-2 border border-gray-300 rounded-lg bg-gray-50 p-4 text-sm text-gray-800 whitespace-pre-wrap">
34+
Résultat…
35+
</pre>
36+
</div>
37+
</div>
2438

2539
<script>
2640
const btn = document.getElementById('btn');
@@ -44,4 +58,5 @@ <h1>Test de l'API d'analyse de sentiments</h1>
4458
};
4559
</script>
4660
</body>
61+
4762
</html>

0 commit comments

Comments
 (0)