Spaces:
Runtime error
Runtime error
Commit
·
56eafc1
1
Parent(s):
ed66e23
Update main.py
Browse files
main.py
CHANGED
@@ -27,9 +27,15 @@ class InputData(BaseModel):
|
|
27 |
top_p: float = 0.95
|
28 |
repetition_penalty: float = 1.0
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
def format_prompt(message, history):
|
31 |
prompt = "<s>"
|
32 |
-
|
33 |
#with open('Manuale.txt', 'r') as file:
|
34 |
# manual_content = file.read()
|
35 |
# prompt += f"Leggi questo manuale dopo ti farò delle domande: {manual_content}"
|
@@ -52,31 +58,26 @@ def read_root(request: Request, input_data: InputData):
|
|
52 |
|
53 |
history = [] # Puoi definire la history se necessario
|
54 |
generated_response = generate(input_text, history, temperature, max_new_tokens, top_p, repetition_penalty)
|
55 |
-
return
|
56 |
|
57 |
-
@app.
|
58 |
-
def generate_image():
|
59 |
client = Client("https://openskyml-fast-sdxl-stable-diffusion-xl.hf.space/--replicas/545b5tw7n/")
|
60 |
result = client.predict(
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
1024,
|
66 |
1024,
|
67 |
-
|
68 |
fn_index=0
|
69 |
)
|
70 |
image_url = result
|
71 |
with open(image_url, 'rb') as img_file:
|
72 |
img_binary = img_file.read()
|
73 |
img_base64 = base64.b64encode(img_binary).decode('utf-8')
|
74 |
-
return
|
75 |
-
|
76 |
-
@app.get("/Test")
|
77 |
-
def generate_image():
|
78 |
-
result = "a giant monster hybrid of dragon and spider, in dark dense foggy forest "
|
79 |
-
return {"response": result}
|
80 |
|
81 |
@app.get("/")
|
82 |
def read_general():
|
|
|
27 |
top_p: float = 0.95
|
28 |
repetition_penalty: float = 1.0
|
29 |
|
30 |
+
class InputImage(BaseModel):
|
31 |
+
input: str
|
32 |
+
negativePrompt: str = ''
|
33 |
+
steps: int = 25
|
34 |
+
cfg: int = 5
|
35 |
+
seed: int = 453666937
|
36 |
+
|
37 |
def format_prompt(message, history):
|
38 |
prompt = "<s>"
|
|
|
39 |
#with open('Manuale.txt', 'r') as file:
|
40 |
# manual_content = file.read()
|
41 |
# prompt += f"Leggi questo manuale dopo ti farò delle domande: {manual_content}"
|
|
|
58 |
|
59 |
history = [] # Puoi definire la history se necessario
|
60 |
generated_response = generate(input_text, history, temperature, max_new_tokens, top_p, repetition_penalty)
|
61 |
+
return generated_response
|
62 |
|
63 |
+
@app.post("/Immagine")
|
64 |
+
def generate_image(request: Request, input_data: InputImage):
|
65 |
client = Client("https://openskyml-fast-sdxl-stable-diffusion-xl.hf.space/--replicas/545b5tw7n/")
|
66 |
result = client.predict(
|
67 |
+
input_data.input,
|
68 |
+
input_data.negativePrompt,
|
69 |
+
input_data.steps,
|
70 |
+
input_data.cfg,
|
71 |
1024,
|
72 |
1024,
|
73 |
+
input_data.seed,
|
74 |
fn_index=0
|
75 |
)
|
76 |
image_url = result
|
77 |
with open(image_url, 'rb') as img_file:
|
78 |
img_binary = img_file.read()
|
79 |
img_base64 = base64.b64encode(img_binary).decode('utf-8')
|
80 |
+
return img_base64
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
@app.get("/")
|
83 |
def read_general():
|