Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -28,18 +28,19 @@ app.add_middleware(
|
|
28 |
|
29 |
class InputData(BaseModel):
|
30 |
input: str
|
31 |
-
temperature: float = 0.
|
32 |
max_new_tokens: int = 30000
|
33 |
top_p: float = 0.95
|
34 |
repetition_penalty: float = 1.0
|
35 |
|
36 |
class InputDataAsync(BaseModel):
|
37 |
input: str
|
38 |
-
temperature: float = 0.
|
39 |
max_new_tokens: int = 30000
|
40 |
top_p: float = 0.95
|
41 |
repetition_penalty: float = 1.0
|
42 |
NumeroGenerazioni: int = 1
|
|
|
43 |
|
44 |
class PostSpazio(BaseModel):
|
45 |
nomeSpazio: str
|
@@ -89,17 +90,9 @@ def format_prompt(message, history):
|
|
89 |
@app.post("/GeneraAsync")
|
90 |
def read_rootAsync(request: Request, input_data: InputDataAsync):
|
91 |
print(input_data.input)
|
92 |
-
|
93 |
-
'input': input_data.input,
|
94 |
-
'temperature': input_data.temperature,
|
95 |
-
'max_new_tokens': input_data.max_new_tokens,
|
96 |
-
'top_p': input_data.top_p,
|
97 |
-
'repetition_penalty': input_data.repetition_penalty
|
98 |
-
}
|
99 |
-
result_data = asyncio.run(GeneraTestoAsync("https://matteoscript-fastapi.hf.space/Genera", data, input_data.NumeroGenerazioni))
|
100 |
return {"response": result_data}
|
101 |
|
102 |
-
#--------------------------------------------------- Chiamata API Asincrona ------------------------------------------------------
|
103 |
async def make_request(session, token, data, url):
|
104 |
headers = {
|
105 |
'Content-Type': 'application/json',
|
@@ -110,10 +103,17 @@ async def make_request(session, token, data, url):
|
|
110 |
print(result_data)
|
111 |
return result_data
|
112 |
|
113 |
-
async def GeneraTestoAsync(url,
|
114 |
token = os.getenv('TOKEN')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
async with aiohttp.ClientSession() as session:
|
116 |
-
tasks = [make_request(session, token, data, url) for _ in range(NumeroGenerazioni)]
|
117 |
return await asyncio.gather(*tasks)
|
118 |
|
119 |
#--------------------------------------------------- Generazione IMMAGINE ------------------------------------------------------
|
|
|
28 |
|
29 |
class InputData(BaseModel):
|
30 |
input: str
|
31 |
+
temperature: float = 0.7
|
32 |
max_new_tokens: int = 30000
|
33 |
top_p: float = 0.95
|
34 |
repetition_penalty: float = 1.0
|
35 |
|
36 |
class InputDataAsync(BaseModel):
|
37 |
input: str
|
38 |
+
temperature: float = 0.7
|
39 |
max_new_tokens: int = 30000
|
40 |
top_p: float = 0.95
|
41 |
repetition_penalty: float = 1.0
|
42 |
NumeroGenerazioni: int = 1
|
43 |
+
StringaSplit: str = ''
|
44 |
|
45 |
class PostSpazio(BaseModel):
|
46 |
nomeSpazio: str
|
|
|
90 |
@app.post("/GeneraAsync")
|
91 |
def read_rootAsync(request: Request, input_data: InputDataAsync):
|
92 |
print(input_data.input)
|
93 |
+
result_data = asyncio.run(GeneraTestoAsync("https://matteoscript-fastapi.hf.space/Genera", input_data))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
return {"response": result_data}
|
95 |
|
|
|
96 |
async def make_request(session, token, data, url):
|
97 |
headers = {
|
98 |
'Content-Type': 'application/json',
|
|
|
103 |
print(result_data)
|
104 |
return result_data
|
105 |
|
106 |
+
async def GeneraTestoAsync(url, input_data):
|
107 |
token = os.getenv('TOKEN')
|
108 |
+
data = {
|
109 |
+
'input': input_data.input,
|
110 |
+
'temperature': input_data.temperature,
|
111 |
+
'max_new_tokens': input_data.max_new_tokens,
|
112 |
+
'top_p': input_data.top_p,
|
113 |
+
'repetition_penalty': input_data.repetition_penalty
|
114 |
+
}
|
115 |
async with aiohttp.ClientSession() as session:
|
116 |
+
tasks = [make_request(session, token, data, url) for _ in range(input_data.NumeroGenerazioni)]
|
117 |
return await asyncio.gather(*tasks)
|
118 |
|
119 |
#--------------------------------------------------- Generazione IMMAGINE ------------------------------------------------------
|