Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Installer les dépendances si nécessaire
|
| 2 |
+
# pip install transformers torch gradio safetensors
|
| 3 |
+
|
| 4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 5 |
+
import torch
|
| 6 |
+
import gradio as gr
|
| 7 |
+
|
| 8 |
+
# Charger le modèle et le tokenizer
|
| 9 |
+
model_name = "Shaheer14326/Fine_tunned_Biogpt"
|
| 10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 11 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto") # "cpu" si pas de GPU
|
| 12 |
+
|
| 13 |
+
# Fonction pour générer du texte
|
| 14 |
+
def generate_text(prompt):
|
| 15 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 16 |
+
outputs = model.generate(
|
| 17 |
+
**inputs,
|
| 18 |
+
max_new_tokens=150,
|
| 19 |
+
do_sample=True,
|
| 20 |
+
temperature=0.7
|
| 21 |
+
)
|
| 22 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 23 |
+
|
| 24 |
+
# Interface Gradio
|
| 25 |
+
iface = gr.Interface(
|
| 26 |
+
fn=generate_text,
|
| 27 |
+
inputs=gr.Textbox(lines=2, placeholder="Pose ta question médicale ici..."),
|
| 28 |
+
outputs="text",
|
| 29 |
+
title="Chatbot Médical avec BioGPT",
|
| 30 |
+
description="Pose des questions médicales et BioGPT génère une réponse."
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# Lancer l'interface
|
| 34 |
+
iface.launch()
|