File size: 2,988 Bytes
6f0c072
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bbfb2ba
6f0c072
 
 
 
 
 
 
bbfb2ba
6f0c072
 
bbfb2ba
6f0c072
 
 
 
 
 
 
 
 
 
 
bbfb2ba
6f0c072
bbfb2ba
 
 
 
 
 
 
 
 
 
6f0c072
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import gradio as gr
import html2text
import google.generativeai as genai
import os

# Configure Gemini API
genai.configure(api_key="your-gemini-api-key-here")
model = genai.GenerativeModel("gemini-pro")

# Prompt template
def build_prompt(content, platform, styles, emotions):
    style_text = ", ".join(styles) if styles else "humanized"
    emotion_text = ", ".join(emotions) if emotions else "genuine"

    return f"""
You are a fermentation enthusiast who has real-world experience.
Take the following HTML content, summarize it, and turn it into a highly engaging {platform} post.
The tone must feel like it’s written by a human—not AI. Be expressive, imperfect, casual, and honest.
Use styles like {style_text}, and include emotional tones like {emotion_text}.
Sound like you're sharing a personal story or tip—not giving a lecture.

Output structure:
1. Title (1 sentence, catchy, personal)
2. Post body: 2–4 paragraphs, casual tone, share what worked/didn’t, and end with a relatable or curious question.

CONTENT TO CONVERT:
\"\"\"{content}\"\"\"
"""

# Function to handle generation
def generate_post(file, platform, styles, emotions):
    if not file:
        return "Please upload a file."

    # Read and convert HTML file
    raw_html = file.read().decode("utf-8")
    plain_text = html2text.html2text(raw_html)

    prompt = build_prompt(plain_text, platform, styles, emotions)
    response = model.generate_content(prompt)
    return response.text

# Gradio UI
with gr.Blocks(title="Reddit/Quora Post Generator") as demo:
    gr.Markdown("## 🔥 Turn your SEO content into humanized Reddit or Quora posts")

    with gr.Row():
        file_input = gr.File(label="Upload HTML file", file_types=[".html"])
        platform = gr.Dropdown(["Reddit", "Quora"], label="Select Platform", value="Reddit")

    with gr.Row():
        styles = gr.CheckboxGroup(
            ["Humanized", "Friendly", "Personal/Storytelling"],
            label="Writing Style",
            value=["Humanized"]
        )
        emotions = gr.CheckboxGroup(
            ["Curious", "Enthusiastic", "Skeptical", "Inspiring"],
            label="Emotional Tone",
            value=["Curious"]
        )

    generate_btn = gr.Button("Generate Post")
    output = gr.Textbox(label="Generated Post", lines=15)

    with gr.Row():
        download_html = gr.File(label="Download as .html", interactive=False)
        download_txt = gr.File(label="Download as .txt", interactive=False)

    def download_outputs(content):
        html_path = "/tmp/post_output.html"
        txt_path = "/tmp/post_output.txt"
        with open(html_path, "w") as f:
            f.write(content)
        with open(txt_path, "w") as f:
            f.write(content)
        return html_path, txt_path

    generate_btn.click(fn=generate_post, inputs=[file_input, platform, styles, emotions], outputs=output)
    output.change(fn=download_outputs, inputs=output, outputs=[download_html, download_txt])

demo.launch()