Spaces:
Sleeping
Sleeping
Pooja P
commited on
Commit
Β·
998184c
1
Parent(s):
afd1e00
added download and copuy button
Browse files
app.py
CHANGED
@@ -25,7 +25,7 @@ Structure the blog with:
|
|
25 |
- 2β3 subheadings with paragraphs
|
26 |
- A conclusion
|
27 |
|
28 |
-
|
29 |
|
30 |
### Response:
|
31 |
"""
|
@@ -49,10 +49,44 @@ Structure the blog with:
|
|
49 |
return f"β Failed to generate blog: {str(e)}"
|
50 |
|
51 |
# Gradio Interface
|
52 |
-
gr.Interface(
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
).launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
- 2β3 subheadings with paragraphs
|
26 |
- A conclusion
|
27 |
|
28 |
+
Use markdown formatting with ## for subheadings. Keep the tone conversational.
|
29 |
|
30 |
### Response:
|
31 |
"""
|
|
|
49 |
return f"β Failed to generate blog: {str(e)}"
|
50 |
|
51 |
# Gradio Interface
|
52 |
+
# gr.Interface(
|
53 |
+
# fn=generate_blog,
|
54 |
+
# inputs=gr.Textbox(label="Blog Topic"),
|
55 |
+
# outputs=gr.Textbox(label="Generated Blog"),
|
56 |
+
# title="π AI Blog Writer",
|
57 |
+
# description="Enter a topic and get a well-written blog post.",
|
58 |
+
# ).launch(share=True)
|
59 |
+
|
60 |
+
# Gradio Blocks version to add extra buttons
|
61 |
+
with gr.Blocks() as demo:
|
62 |
+
gr.Markdown("## π AI Blog Writer\nEnter a topic and get a well-written blog post.")
|
63 |
+
|
64 |
+
with gr.Row():
|
65 |
+
topic_input = gr.Textbox(label="Blog Topic", placeholder="e.g. Clean energy")
|
66 |
+
|
67 |
+
with gr.Row():
|
68 |
+
generate_btn = gr.Button("βοΈ Generate Blog")
|
69 |
+
|
70 |
+
blog_output = gr.Textbox(label="Generated Blog", lines=20)
|
71 |
+
|
72 |
+
with gr.Row():
|
73 |
+
copy_btn = gr.Button("π Copy to Clipboard")
|
74 |
+
download_btn = gr.Button("β¬οΈ Download Blog")
|
75 |
+
|
76 |
+
download_file = gr.File(label="Download", visible=False)
|
77 |
+
|
78 |
+
def copy_text(text):
|
79 |
+
# No-op: client handles clipboard via JS
|
80 |
+
return text
|
81 |
+
|
82 |
+
def download_blog(text):
|
83 |
+
filepath = "generated_blog.txt"
|
84 |
+
with open(filepath, "w", encoding="utf-8") as f:
|
85 |
+
f.write(text)
|
86 |
+
return filepath
|
87 |
+
|
88 |
+
generate_btn.click(fn=generate_blog, inputs=topic_input, outputs=blog_output)
|
89 |
+
copy_btn.click(fn=copy_text, inputs=blog_output, outputs=blog_output)
|
90 |
+
download_btn.click(fn=download_blog, inputs=blog_output, outputs=download_file)
|
91 |
+
|
92 |
+
demo.launch(share=True)
|