Spaces:
Sleeping
Sleeping
download_content
Browse files- app.py +31 -1
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,9 +1,11 @@
|
|
1 |
import os
|
|
|
2 |
import gradio as gr
|
3 |
from openai import OpenAI
|
4 |
|
5 |
-
from difflib import Differ
|
6 |
import random
|
|
|
|
|
7 |
|
8 |
import json
|
9 |
import tempfile
|
@@ -650,6 +652,21 @@ def generate_chinese_essay_idea(model, user_prompt, chinese_essay_title_input):
|
|
650 |
return content
|
651 |
|
652 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
653 |
def init_params(request: gr.Request):
|
654 |
if request:
|
655 |
print("Request headers dictionary:", request.headers)
|
@@ -1593,6 +1610,19 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
1593 |
with gr.Column():
|
1594 |
with gr.Row():
|
1595 |
gr.Markdown("# Step 9. 寫作完成 Save and Share")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1596 |
with gr.Row():
|
1597 |
gr.Markdown("## 完成修訂!你按部就班地完成了一次段落寫作練習,太棒了!")
|
1598 |
with gr.Row():
|
|
|
1 |
import os
|
2 |
+
from docx import Document
|
3 |
import gradio as gr
|
4 |
from openai import OpenAI
|
5 |
|
|
|
6 |
import random
|
7 |
+
import uuid
|
8 |
+
|
9 |
|
10 |
import json
|
11 |
import tempfile
|
|
|
652 |
return content
|
653 |
|
654 |
|
655 |
+
# Download doc
|
656 |
+
def create_word(content):
|
657 |
+
unique_filename = str(uuid.uuid4())
|
658 |
+
word_file_path = f"/tmp/{unique_filename}.docx"
|
659 |
+
doc = Document()
|
660 |
+
doc.add_paragraph(content)
|
661 |
+
doc.save(word_file_path)
|
662 |
+
return word_file_path
|
663 |
+
|
664 |
+
def download_content(content):
|
665 |
+
word_path = create_word(content)
|
666 |
+
return word_path
|
667 |
+
|
668 |
+
|
669 |
+
# === INIT PARAMS ===
|
670 |
def init_params(request: gr.Request):
|
671 |
if request:
|
672 |
print("Request headers dictionary:", request.headers)
|
|
|
1610 |
with gr.Column():
|
1611 |
with gr.Row():
|
1612 |
gr.Markdown("# Step 9. 寫作完成 Save and Share")
|
1613 |
+
with gr.Row():
|
1614 |
+
# 顯示最後段落寫作結果
|
1615 |
+
with gr.Column():
|
1616 |
+
paragraph_save_to_doc_button = gr.Button("點擊建立 doc", variant="primary")
|
1617 |
+
with gr.Column():
|
1618 |
+
paragraph_doc_download_link = gr.File(label="請點擊右下角連結(ex: 37KB),進行下載")
|
1619 |
+
|
1620 |
+
paragraph_save_to_doc_button.click(
|
1621 |
+
fn=download_content,
|
1622 |
+
inputs=[paragraph_refine_input],
|
1623 |
+
outputs=[paragraph_doc_download_link]
|
1624 |
+
)
|
1625 |
+
|
1626 |
with gr.Row():
|
1627 |
gr.Markdown("## 完成修訂!你按部就班地完成了一次段落寫作練習,太棒了!")
|
1628 |
with gr.Row():
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
gradio==4.37.2
|
2 |
-
openai>=1.16.2
|
|
|
|
1 |
gradio==4.37.2
|
2 |
+
openai>=1.16.2
|
3 |
+
python-docx
|