R-Kentaren commited on
Commit
b71e6e4
·
verified ·
1 Parent(s): a88bfcf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -4
app.py CHANGED
@@ -27,7 +27,7 @@ import time
27
  import traceback
28
  from pathlib import Path
29
  from typing import Any, Dict, List, Optional
30
-
31
  from fastapi import FastAPI, Request
32
  from fastapi.responses import HTMLResponse, JSONResponse
33
  from fastapi.staticfiles import StaticFiles
@@ -40,9 +40,6 @@ from transformers import (
40
  AutoTokenizer,
41
  )
42
 
43
- # Optional: transformers.agents (used as a hint only — the agent loop below
44
- # is implemented manually to keep it dependency-free and to work even when
45
- # transformers.agents is unavailable).
46
  try:
47
  from transformers.agents import ReactAgent, TransformersModel, tool # noqa
48
  AGENT_AVAILABLE = True
@@ -223,6 +220,7 @@ def _build_prompt(model_id: str, messages: List[Dict[str, Any]],
223
  return "\n".join(f"{m['role']}: {m['content']}" for m in flat_messages) + "\nassistant:"
224
 
225
 
 
226
  def generate(model_id: str, messages: List[Dict[str, Any]],
227
  system_prompt: str, max_tokens: int, temperature: float,
228
  top_p: float = 0.95) -> str:
 
27
  import traceback
28
  from pathlib import Path
29
  from typing import Any, Dict, List, Optional
30
+ import spaces
31
  from fastapi import FastAPI, Request
32
  from fastapi.responses import HTMLResponse, JSONResponse
33
  from fastapi.staticfiles import StaticFiles
 
40
  AutoTokenizer,
41
  )
42
 
 
 
 
43
  try:
44
  from transformers.agents import ReactAgent, TransformersModel, tool # noqa
45
  AGENT_AVAILABLE = True
 
220
  return "\n".join(f"{m['role']}: {m['content']}" for m in flat_messages) + "\nassistant:"
221
 
222
 
223
+ @spaces.GPU
224
  def generate(model_id: str, messages: List[Dict[str, Any]],
225
  system_prompt: str, max_tokens: int, temperature: float,
226
  top_p: float = 0.95) -> str: