Spaces:
Sleeping
Sleeping
Commit ·
2e60f04
1
Parent(s): 3a407a6
Ajout du modèle de captioning PaliGemma 2
Browse files
app.py
CHANGED
|
@@ -1,47 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import hf_hub_download
|
| 3 |
from ctransformers import AutoModelForCausalLM
|
| 4 |
-
import base64
|
| 5 |
-
from PIL import Image
|
| 6 |
-
import io
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
print("📥 Téléchargement du modèle...")
|
| 12 |
model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE)
|
| 13 |
|
| 14 |
print("⚙️ Chargement...")
|
| 15 |
llm = AutoModelForCausalLM.from_pretrained(
|
| 16 |
model_path,
|
| 17 |
-
model_type="mistral",
|
| 18 |
threads=2,
|
| 19 |
context_length=2048,
|
| 20 |
max_new_tokens=256
|
| 21 |
)
|
|
|
|
| 22 |
|
| 23 |
def respond(message, history):
|
| 24 |
-
|
|
|
|
| 25 |
response = llm(prompt, temperature=0.7, max_new_tokens=256)
|
| 26 |
return response.strip()
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
with gr.Blocks() as demo:
|
| 35 |
-
gr.Markdown("# 🤖 Assistant Mistral Vision (français + images)")
|
| 36 |
-
|
| 37 |
-
with gr.Tab("Chat texte"):
|
| 38 |
-
chat = gr.ChatInterface(fn=respond)
|
| 39 |
-
|
| 40 |
-
with gr.Tab("Analyse d'image"):
|
| 41 |
-
image_input = gr.Image(type="pil", label="Votre image")
|
| 42 |
-
text_input = gr.Textbox(label="Question sur l'image", placeholder="Que voyez-vous sur cette image ?")
|
| 43 |
-
output = gr.Textbox(label="Réponse")
|
| 44 |
-
submit = gr.Button("Analyser")
|
| 45 |
-
submit.click(fn=image_respond, inputs=[image_input, text_input], outputs=output)
|
| 46 |
|
| 47 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import hf_hub_download
|
| 3 |
from ctransformers import AutoModelForCausalLM
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
# French-Alpaca - modéle français confirmé
|
| 6 |
+
MODEL_REPO = "jpacifico/french-alpaca-instruct-Q4-GGUF"
|
| 7 |
+
MODEL_FILE = "french-alpaca-instruct-Q4.gguf"
|
| 8 |
|
| 9 |
+
print("📥 Téléchargement du modèle français...")
|
| 10 |
model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE)
|
| 11 |
|
| 12 |
print("⚙️ Chargement...")
|
| 13 |
llm = AutoModelForCausalLM.from_pretrained(
|
| 14 |
model_path,
|
| 15 |
+
model_type="mistral", # French-Alpaca est basé sur Mistral
|
| 16 |
threads=2,
|
| 17 |
context_length=2048,
|
| 18 |
max_new_tokens=256
|
| 19 |
)
|
| 20 |
+
print("✅ Modèle français chargé !")
|
| 21 |
|
| 22 |
def respond(message, history):
|
| 23 |
+
# Format du prompt adapté
|
| 24 |
+
prompt = f"### Instruction:\n{message}\n\n### Response:\n"
|
| 25 |
response = llm(prompt, temperature=0.7, max_new_tokens=256)
|
| 26 |
return response.strip()
|
| 27 |
|
| 28 |
+
demo = gr.ChatInterface(
|
| 29 |
+
fn=respond,
|
| 30 |
+
title="🤖 Assistant Français (French-Alpaca)",
|
| 31 |
+
description="Modèle entraîné spécifiquement pour le français"
|
| 32 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|