Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,8 @@ def query(payload):
|
|
15 |
|
16 |
def generate_and_append_text(max_length):
|
17 |
global generated_text
|
|
|
|
|
18 |
parameters = {
|
19 |
"max_new_tokens": max_length,
|
20 |
"top_p": 0.9,
|
@@ -24,14 +26,15 @@ def generate_and_append_text(max_length):
|
|
24 |
"length_penalty": 0.0,
|
25 |
"eos_token_id": None,
|
26 |
}
|
27 |
-
payload = {"inputs":
|
28 |
data = query(payload)
|
29 |
if "error" in data:
|
30 |
return f"<span style='color:red'>ERROR: {data['error']} </span>"
|
31 |
-
new_text = data[0]["generated_text"].replace(
|
32 |
-
generated_text += " " + new_text
|
33 |
return generated_text
|
34 |
|
|
|
35 |
if __name__ == "__main__":
|
36 |
demo = gr.Blocks()
|
37 |
with demo:
|
|
|
15 |
|
16 |
def generate_and_append_text(max_length):
|
17 |
global generated_text
|
18 |
+
# Ensure that the input is not empty
|
19 |
+
input_text = generated_text if generated_text.strip() else " "
|
20 |
parameters = {
|
21 |
"max_new_tokens": max_length,
|
22 |
"top_p": 0.9,
|
|
|
26 |
"length_penalty": 0.0,
|
27 |
"eos_token_id": None,
|
28 |
}
|
29 |
+
payload = {"inputs": input_text, "parameters": parameters, "options": {"use_cache": False}}
|
30 |
data = query(payload)
|
31 |
if "error" in data:
|
32 |
return f"<span style='color:red'>ERROR: {data['error']} </span>"
|
33 |
+
new_text = data[0]["generated_text"].replace(input_text, "").strip()
|
34 |
+
generated_text += " " + new_text if generated_text.strip() else new_text
|
35 |
return generated_text
|
36 |
|
37 |
+
|
38 |
if __name__ == "__main__":
|
39 |
demo = gr.Blocks()
|
40 |
with demo:
|