Spaces:
Sleeping
Sleeping
Update main.py
Browse files27 unmodified lines28293031313233343536373838394041424344454643 unmodified lines90919292939495969798999394951029697984 unmodified lines10310410511310610710810911011111211311411511611611711811927 unmodified lines
class InputData(BaseModel): input: str temperature: float = 0.2 temperature: float = 0.7 max_new_tokens: int = 30000 top_p: float = 0.95 repetition_penalty: float = 1.0
class InputDataAsync(BaseModel): input: str temperature: float = 0.2 temperature: float = 0.7 max_new_tokens: int = 30000 top_p: float = 0.95 repetition_penalty: float = 1.0 NumeroGenerazioni: int = 1 StringaSplit: str = '' class PostSpazio(BaseModel): nomeSpazio: str43 unmodified lines@app.post("/GeneraAsync")def read_rootAsync(request: Request, input_data: InputDataAsync): print(input_data.input) data = { 'input': input_data.input, 'temperature': input_data.temperature, 'max_new_tokens': input_data.max_new_tokens, 'top_p': input_data.top_p, 'repetition_penalty': input_data.repetition_penalty } result_data = asyncio.run(GeneraTestoAsync("https://matteoscript-fastapi.hf.space/Genera", data, input_data.NumeroGenerazioni)) result_data = asyncio.run(GeneraTestoAsync("https://matteoscript-fastapi.hf.space/Genera", input_data)) return {"response": result_data}
#--------------------------------------------------- Chiamata API Asincrona ------------------------------------------------------async def make_request(session, token, data, url): headers = { 'Content-Type': 'application/json',4 unmodified lines print(result_data) return result_data
async def GeneraTestoAsync(url, data, NumeroGenerazioni):async def GeneraTestoAsync(url, input_data): token = os.getenv('TOKEN') data = { 'input': input_data.input, 'temperature': input_data.temperature, 'max_new_tokens': input_data.max_new_tokens, 'top_p': input_data.top_p, 'repetition_penalty': input_data.repetition_penalty } async with aiohttp.ClientSession() as session: tasks = [make_request(session, token, data, url) for _ in range(NumeroGenerazioni)] tasks = [make_request(session, token, data, url) for _ in range(input_data.NumeroGenerazioni)] return await asyncio.gather(*tasks) #--------------------------------------------------- Generazione IMMAGINE ------------------------------------------------------main.py+13-13