danielramos commited on
Commit
c5ebddd
·
1 Parent(s): a80c040

feat: add @spaces.GPU decorator for Hugging Face ZeroGPU compatibility

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -8,6 +8,20 @@ from main import (
8
  app as fastapi_app
9
  )
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  def chat_fn(message, history):
12
  messages = [SystemMessage(content=DEFAULT_SYSTEM_PROMPT)]
13
  if history:
@@ -34,7 +48,7 @@ def chat_fn(message, history):
34
  demo = gr.ChatInterface(
35
  fn=chat_fn,
36
  title="⚡ Qwen 2.5 (0.5B) • Intelecto Conciso",
37
- description="Chatbot superinteligente, hiperpreciso y conciso en español. Orquestado con LangGraph y llama-cpp-python en Hugging Face Spaces.",
38
  examples=["¿Qué es la entropía?", "¿Por qué el cielo es azul?", "¿Qué es la vida?"],
39
  )
40
 
@@ -42,5 +56,4 @@ demo = gr.ChatInterface(
42
  demo.app.include_router(fastapi_app.router)
43
 
44
  if __name__ == "__main__":
45
- # demo.launch() detecta automáticamente el puerto y entorno asignado por Hugging Face ZeroGPU
46
  demo.launch()
 
8
  app as fastapi_app
9
  )
10
 
11
+ # Soporte para Hugging Face ZeroGPU
12
+ try:
13
+ import spaces
14
+ except ImportError:
15
+ class spaces:
16
+ @staticmethod
17
+ def GPU(func=None, duration=None):
18
+ if func is not None:
19
+ return func
20
+ def decorator(f):
21
+ return f
22
+ return decorator
23
+
24
+ @spaces.GPU
25
  def chat_fn(message, history):
26
  messages = [SystemMessage(content=DEFAULT_SYSTEM_PROMPT)]
27
  if history:
 
48
  demo = gr.ChatInterface(
49
  fn=chat_fn,
50
  title="⚡ Qwen 2.5 (0.5B) • Intelecto Conciso",
51
+ description="Chatbot superinteligente, hiperpreciso y conciso en español. Orquestado con LangGraph y llama-cpp-python en Hugging Face Spaces (ZeroGPU).",
52
  examples=["¿Qué es la entropía?", "¿Por qué el cielo es azul?", "¿Qué es la vida?"],
53
  )
54
 
 
56
  demo.app.include_router(fastapi_app.router)
57
 
58
  if __name__ == "__main__":
 
59
  demo.launch()