what-time-is-it-tool / random_charactor_generator.py
Chris4K's picture
Update random_charactor_generator.py
7ad917c verified
raw
history blame
1.52 kB
import requests
from transformers import Tool
class RandomCharatorGeneratorTool(Tool):
name = "random_character"
description = "This tool generates a random character. Returns json."
inputs = ["text"] # Adding an empty list for inputs
outputs = ["html"]
def __init__(self, device=None, **hub_kwargs) -> None:
#if not is_accelerate_available():
# raise ImportError("Accelerate should be installed in order to use tools.")
super().__init__()
self.device = device
self.pipeline = None
self.hub_kwargs = hub_kwargs
def setup(self):
#if self.device is None:
# self.device = get_default_device()
#self.pipeline = DiffusionPipeline.from_pretrained(self.default_checkpoint)
#self.pipeline.scheduler = DPMSolverMultistepScheduler.from_config(self.pipeline.scheduler.config)
#self.pipeline.to(self.device)
#if self.device.type == "cuda":
# self.pipeline.to(torch_dtype=torch.float16)
self.is_initialized = True
def __call__(self, input:str="", *args, **kwargs):
text = '''
// Get the current time
<span id=time></span>
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
// Add the time to a HTML element
document.querySelector('#time').innerText = hours + ':' + minutes + ':' + seconds;"
'''
return text