Spaces:
Runtime error
Runtime error
Commit
•
a89aa0d
1
Parent(s):
296f852
Add application file
Browse files- app_huggingface_spaces.py +24 -0
app_huggingface_spaces.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
|
4 |
+
# Cargar el modelo y el tokenizer
|
5 |
+
model_name = "epfl-llm/meditron-7b"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# Función para generar respuesta del modelo
|
10 |
+
def generate_response(prompt):
|
11 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
12 |
+
outputs = model.generate(inputs.input_ids, max_length=200, pad_token_id=tokenizer.eos_token_id)
|
13 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
14 |
+
return response
|
15 |
+
|
16 |
+
# Configurar la interfaz de Gradio
|
17 |
+
def chat(paciente_input):
|
18 |
+
prompt = f"Paciente: {paciente_input}\nDoctor:"
|
19 |
+
response = generate_response(prompt)
|
20 |
+
return response
|
21 |
+
|
22 |
+
iface = gr.Interface(fn=chat, inputs="text", outputs="text", title="Consulta Médica con Meditron-7B")
|
23 |
+
|
24 |
+
iface.launch()
|