susanazhou commited on
Commit
ee8e544
verified
1 Parent(s): aa76845

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -7,16 +7,16 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
7
  model_id = "somosnlp-hackathon-2025/leia_preference_model_social_norms"
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
9
 
10
- # Obtener el token secreto del entorno
11
  hf_token = os.environ.get("SSNZHY_TOKEN")
 
 
12
 
13
  # Cargar modelo y tokenizer con autenticaci贸n
14
  tokenizer = AutoTokenizer.from_pretrained(model_id, token=hf_token)
15
  model = AutoModelForCausalLM.from_pretrained(model_id, token=hf_token).to(device)
16
 
17
-
18
-
19
- # Funci贸n para responder
20
  def respond(message, history, system_message, max_tokens, temperature, top_p):
21
  prompt = system_message + "\n"
22
  for user, assistant in history:
@@ -39,6 +39,7 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
39
 
40
 
41
 
 
42
  # Descripci贸n del proyecto
43
  descripcion = """
44
 
@@ -100,20 +101,32 @@ En **LeIA GO**, somos conscientes de que los modelos de lenguaje pueden reflejar
100
  - Dataset: [https://huggingface.co/datasets/somosnlp-hackathon-2025/dataset-preferencias-v0]
101
  """
102
 
103
- # Interfaz Gradio
104
  with gr.Blocks() as demo:
105
  with gr.Tab("Descripci贸n del Proyecto"):
106
  gr.Markdown(descripcion)
 
107
  with gr.Tab("Chatbot LeIA GO"):
 
108
  gr.ChatInterface(
109
  respond,
110
  additional_inputs=[
111
- gr.Textbox(value="Eres una asistente ling眉铆stica especializada en espa帽ol regional.", label="System message"),
 
 
 
112
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
113
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
114
  gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
115
  ],
116
  )
117
 
 
118
  if __name__ == "__main__":
119
- demo.launch()
 
 
 
 
 
 
 
7
  model_id = "somosnlp-hackathon-2025/leia_preference_model_social_norms"
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
9
 
10
+ # Obtener el token desde variable de entorno
11
  hf_token = os.environ.get("SSNZHY_TOKEN")
12
+ if not hf_token:
13
+ raise ValueError("El token de Hugging Face no est谩 definido. Configura la variable de entorno 'SSNZHY_TOKEN'.")
14
 
15
  # Cargar modelo y tokenizer con autenticaci贸n
16
  tokenizer = AutoTokenizer.from_pretrained(model_id, token=hf_token)
17
  model = AutoModelForCausalLM.from_pretrained(model_id, token=hf_token).to(device)
18
 
19
+ # Funci贸n de respuesta del chatbot
 
 
20
  def respond(message, history, system_message, max_tokens, temperature, top_p):
21
  prompt = system_message + "\n"
22
  for user, assistant in history:
 
39
 
40
 
41
 
42
+
43
  # Descripci贸n del proyecto
44
  descripcion = """
45
 
 
101
  - Dataset: [https://huggingface.co/datasets/somosnlp-hackathon-2025/dataset-preferencias-v0]
102
  """
103
 
104
+ # Interfaz con Gradio
105
  with gr.Blocks() as demo:
106
  with gr.Tab("Descripci贸n del Proyecto"):
107
  gr.Markdown(descripcion)
108
+
109
  with gr.Tab("Chatbot LeIA GO"):
110
+ gr.Markdown("### 馃憢 Bienvenida a LeIA GO\nChatea con una IA especializada en normas sociales y variantes del espa帽ol.")
111
  gr.ChatInterface(
112
  respond,
113
  additional_inputs=[
114
+ gr.Textbox(
115
+ value="Eres una asistente ling眉铆stica especializada en espa帽ol regional.",
116
+ label="Mensaje del sistema"
117
+ ),
118
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
119
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
120
  gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
121
  ],
122
  )
123
 
124
+ # Lanzamiento
125
  if __name__ == "__main__":
126
+ demo.launch(
127
+ show_api=False,
128
+ share=False,
129
+ title="LeIA GO - Chat de Normas Sociales",
130
+ theme=gr.themes.Base()
131
+ )
132
+