Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,7 +25,7 @@ def generate_post_periodically():
|
|
| 25 |
])
|
| 26 |
result = generator(prompt, max_length=30, num_return_sequences=1)
|
| 27 |
text = result[0]['generated_text'].strip().replace("\n", " ")
|
| 28 |
-
posts.append(text[:100])
|
| 29 |
if len(posts) > 10:
|
| 30 |
posts.pop(0)
|
| 31 |
time.sleep(random.randint(5, 15))
|
|
@@ -51,10 +51,14 @@ with gr.Blocks() as interface:
|
|
| 51 |
post_box = gr.Textbox(label="Recent Posts", lines=10)
|
| 52 |
stop_btn = gr.Button("STOP & ERASE MEMORY")
|
| 53 |
|
| 54 |
-
# ربط الزر بالدالة
|
| 55 |
stop_btn.click(stop_and_erase, outputs=post_box)
|
| 56 |
|
| 57 |
-
# تحديث النصوص
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
interface.launch()
|
|
|
|
| 25 |
])
|
| 26 |
result = generator(prompt, max_length=30, num_return_sequences=1)
|
| 27 |
text = result[0]['generated_text'].strip().replace("\n", " ")
|
| 28 |
+
posts.append(text[:100])
|
| 29 |
if len(posts) > 10:
|
| 30 |
posts.pop(0)
|
| 31 |
time.sleep(random.randint(5, 15))
|
|
|
|
| 51 |
post_box = gr.Textbox(label="Recent Posts", lines=10)
|
| 52 |
stop_btn = gr.Button("STOP & ERASE MEMORY")
|
| 53 |
|
|
|
|
| 54 |
stop_btn.click(stop_and_erase, outputs=post_box)
|
| 55 |
|
| 56 |
+
# تحديث النصوص كل ثانية عن طريق Thread داخل واجهة Gradio
|
| 57 |
+
def refresh_box():
|
| 58 |
+
while True:
|
| 59 |
+
post_box.value = get_posts()
|
| 60 |
+
time.sleep(1)
|
| 61 |
+
|
| 62 |
+
threading.Thread(target=refresh_box, daemon=True).start()
|
| 63 |
|
| 64 |
interface.launch()
|