Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import os
|
2 |
from huggingface_hub import login
|
3 |
|
4 |
-
#
|
5 |
hf_token = os.environ.get("HUGGINGFACE_API_KEY")
|
6 |
login(hf_token)
|
7 |
|
@@ -12,6 +12,7 @@ from PIL import Image
|
|
12 |
|
13 |
model_id = "ContactDoctor/Bio-Medical-MultiModal-Llama-3-8B-V1"
|
14 |
|
|
|
15 |
model = AutoModelForCausalLM.from_pretrained(
|
16 |
model_id,
|
17 |
trust_remote_code=True,
|
@@ -19,11 +20,16 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
19 |
device_map="auto"
|
20 |
)
|
21 |
|
22 |
-
processor
|
|
|
|
|
|
|
|
|
23 |
|
|
|
24 |
def generate_answer(image, question):
|
25 |
if not question or question.strip() == "":
|
26 |
-
|
27 |
|
28 |
prompt = f"### User: {question}\n### Assistant:"
|
29 |
|
@@ -38,6 +44,7 @@ def generate_answer(image, question):
|
|
38 |
except Exception as e:
|
39 |
return f"⚠️ Internal Error: {str(e)}"
|
40 |
|
|
|
41 |
demo = gr.Interface(
|
42 |
fn=generate_answer,
|
43 |
inputs=[
|
@@ -49,4 +56,5 @@ demo = gr.Interface(
|
|
49 |
description="Multimodal Medical Assistant: upload an image and ask a medical question."
|
50 |
)
|
51 |
|
|
|
52 |
demo.launch()
|
|
|
1 |
import os
|
2 |
from huggingface_hub import login
|
3 |
|
4 |
+
# 🔐 Login avec ton token Hugging Face (stocké comme secret)
|
5 |
hf_token = os.environ.get("HUGGINGFACE_API_KEY")
|
6 |
login(hf_token)
|
7 |
|
|
|
12 |
|
13 |
model_id = "ContactDoctor/Bio-Medical-MultiModal-Llama-3-8B-V1"
|
14 |
|
15 |
+
# ✅ Charger le modèle avec custom code autorisé
|
16 |
model = AutoModelForCausalLM.from_pretrained(
|
17 |
model_id,
|
18 |
trust_remote_code=True,
|
|
|
20 |
device_map="auto"
|
21 |
)
|
22 |
|
23 |
+
# ✅ Charger le processor avec trust_remote_code aussi
|
24 |
+
processor = AutoProcessor.from_pretrained(
|
25 |
+
model_id,
|
26 |
+
trust_remote_code=True
|
27 |
+
)
|
28 |
|
29 |
+
# 🧠 Fonction principale d'inférence
|
30 |
def generate_answer(image, question):
|
31 |
if not question or question.strip() == "":
|
32 |
+
question = "Please describe this medical image."
|
33 |
|
34 |
prompt = f"### User: {question}\n### Assistant:"
|
35 |
|
|
|
44 |
except Exception as e:
|
45 |
return f"⚠️ Internal Error: {str(e)}"
|
46 |
|
47 |
+
# 🎛️ Interface Gradio
|
48 |
demo = gr.Interface(
|
49 |
fn=generate_answer,
|
50 |
inputs=[
|
|
|
56 |
description="Multimodal Medical Assistant: upload an image and ask a medical question."
|
57 |
)
|
58 |
|
59 |
+
# 🚀 Lancer l'app
|
60 |
demo.launch()
|