phxdev commited on
Commit
157b527
Β·
verified Β·
1 Parent(s): a4f7581

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +231 -67
README.md CHANGED
@@ -1,68 +1,232 @@
1
- ---
2
- title: AI One-Pager Generator
3
- emoji: πŸ“„
4
- colorFrom: blue
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: "4.44.0"
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- suggested_hardware: t4-small
12
- suggested_storage: small
13
- ---
14
-
15
- # πŸ“„ AI One-Pager Generator
16
-
17
- An intelligent Gradio application that generates professional one-page documents on any topic using Hugging Face transformers.
18
-
19
- ## Features
20
-
21
- - **Topic-based Generation**: Create one-pagers on any subject
22
- - **Customizable Parameters**:
23
- - Target audience specification
24
- - Tone selection (Professional, Casual, Academic, Persuasive, Informative)
25
- - Length control (Short, Medium, Long)
26
- - Key points input
27
- - **Professional Formatting**: Structured output with title, executive summary, key points, and conclusion
28
- - **Easy to Use**: Simple web interface powered by Gradio
29
-
30
- ## Installation
31
-
32
- 1. Clone this repository
33
- 2. Install dependencies:
34
- ```bash
35
- pip install -r requirements.txt
36
- ```
37
-
38
- 3. Run the application:
39
- ```bash
40
- python app.py
41
- ```
42
-
43
- ## Usage
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
- 1. Enter your topic in the "Topic" field
46
- 2. Specify your target audience
47
- 3. List key points you want covered
48
- 4. Select the appropriate tone and length
49
- 5. Click "Generate One-Pager"
50
- 6. Copy and use your generated document!
51
-
52
- ## Deployment to Hugging Face Spaces
53
-
54
- This app is ready to be deployed to Hugging Face Spaces:
55
-
56
- 1. Create a new Space on Hugging Face
57
- 2. Upload these files to your Space
58
- 3. Your app will be automatically deployed!
59
-
60
- ## Model Information
61
-
62
- This application uses Qwen 2.5-Omni-7B, a state-of-the-art 2024/2025 multimodal language model with 7B parameters, specifically optimized for instruction following and high-quality document generation. Fallback models include Qwen 2.5-7B-Instruct and Qwen 2.5-1.5B-Instruct for compatibility across different hardware configurations.
63
-
64
- **Note**: This model performs best on GPU-enabled Spaces for optimal speed and quality.
65
-
66
- ## License
67
-
68
- MIT License
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import torch
4
+ import os
5
+
6
+ # Initialize the text generation pipeline
7
+ generator = None
8
+
9
+ def initialize_model():
10
+ global generator
11
+ try:
12
+ # Start with Qwen 2.5-7B-Instruct (more reliable than Omni for Spaces)
13
+ device = 0 if torch.cuda.is_available() else -1
14
+ generator = pipeline(
15
+ "text-generation",
16
+ model="Qwen/Qwen2.5-7B-Instruct",
17
+ device=device,
18
+ torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
19
+ trust_remote_code=True
20
+ )
21
+ return f"Qwen 2.5-7B-Instruct loaded successfully on {'GPU' if device == 0 else 'CPU'}!"
22
+ except Exception as e:
23
+ # Fallback to 1.5B model
24
+ try:
25
+ generator = pipeline(
26
+ "text-generation",
27
+ model="Qwen/Qwen2.5-1.5B-Instruct",
28
+ device=-1,
29
+ torch_dtype=torch.float32,
30
+ trust_remote_code=True
31
+ )
32
+ return "Fallback model (Qwen 2.5-1.5B-Instruct) loaded on CPU!"
33
+ except Exception as e2:
34
+ # Final fallback to a very reliable model
35
+ try:
36
+ generator = pipeline(
37
+ "text-generation",
38
+ model="microsoft/DialoGPT-large",
39
+ device=-1,
40
+ torch_dtype=torch.float32
41
+ )
42
+ return "Final fallback model (DialoGPT-large) loaded on CPU!"
43
+ except Exception as e3:
44
+ return f"All models failed: 7B: {str(e)}, 1.5B: {str(e2)}, DialoGPT: {str(e3)}"
45
+
46
+ def generate_onepager(topic, target_audience, key_points, tone, length):
47
+ if generator is None:
48
+ return "Error: Model not initialized. Please wait for the model to load."
49
+
50
+ # Create a structured prompt for one-pager generation
51
+ length_tokens = {"Short": 200, "Medium": 400, "Long": 600}
52
+ max_tokens = length_tokens.get(length, 400)
53
+
54
+ # Create an optimized prompt for Qwen 2.5 instruction format
55
+ prompt = f"""<|im_start|>system
56
+ You are a professional document writer specializing in creating concise, well-structured one-page business documents.
57
+ <|im_end|>
58
+ <|im_start|>user
59
+ Create a professional one-page document about "{topic}" targeted at {target_audience}.
60
+
61
+ Requirements:
62
+ - Tone: {tone.lower()}
63
+ - Key points to include: {key_points}
64
+ - Length: {length}
65
+ - Format: Use clear headers and bullet points
66
+ - Structure: Title, Executive Summary, Key Points, Benefits, Recommendations, Conclusion
67
+
68
+ Please write the complete one-page document now.
69
+ <|im_end|>
70
+ <|im_start|>assistant
71
+ # {topic}
72
+
73
+ ## Executive Summary
74
+
75
+ """
76
+
77
+ try:
78
+ # Generate the one-pager
79
+ result = generator(
80
+ prompt,
81
+ max_length=len(prompt.split()) + max_tokens,
82
+ num_return_sequences=1,
83
+ temperature=0.8,
84
+ do_sample=True,
85
+ pad_token_id=generator.tokenizer.eos_token_id,
86
+ eos_token_id=generator.tokenizer.eos_token_id,
87
+ repetition_penalty=1.1
88
+ )
89
+
90
+ # Extract the generated text
91
+ generated_text = result[0]['generated_text']
92
+
93
+ # Clean up the output
94
+ onepager = generated_text.replace(prompt, "").strip()
95
+
96
+ # If output is too short, provide a structured fallback
97
+ if len(onepager) < 50:
98
+ onepager = create_structured_onepager(topic, target_audience, key_points, tone)
99
+
100
+ return onepager
101
+
102
+ except Exception as e:
103
+ # Fallback to structured template
104
+ return create_structured_onepager(topic, target_audience, key_points, tone)
105
+
106
+ def create_structured_onepager(topic, target_audience, key_points, tone):
107
+ """Create a structured one-pager when AI generation fails"""
108
+
109
+ tone_styles = {
110
+ "Professional": "formal and business-oriented",
111
+ "Casual": "friendly and approachable",
112
+ "Academic": "scholarly and research-focused",
113
+ "Persuasive": "compelling and action-oriented",
114
+ "Informative": "clear and educational"
115
+ }
116
+
117
+ style_desc = tone_styles.get(tone, "professional")
118
+
119
+ template = f"""# {topic}
120
+
121
+ ## Executive Summary
122
+ This document provides a comprehensive overview of {topic.lower()} tailored for {target_audience.lower()}. The content is presented in a {style_desc} manner to ensure maximum impact and understanding.
123
+
124
+ ## Key Points
125
+
126
+ {chr(10).join([f"β€’ {point.strip()}" for point in key_points.split(',') if point.strip()])}
127
+
128
+ ## Background
129
+ {topic} represents an important area that requires careful consideration and strategic thinking. Understanding the core concepts and implications is essential for {target_audience.lower()}.
130
+
131
+ ## Main Content
132
+ The fundamental aspects of {topic.lower()} encompass several critical areas that directly impact stakeholders. These elements work together to create a comprehensive framework for understanding and implementation.
133
+
134
+ ## Benefits & Opportunities
135
+ - Enhanced understanding of core concepts
136
+ - Improved decision-making capabilities
137
+ - Strategic advantages for implementation
138
+ - Clear actionable insights
139
+
140
+ ## Recommendations
141
+ 1. Begin with thorough analysis of current situation
142
+ 2. Develop comprehensive implementation strategy
143
+ 3. Monitor progress and adjust approach as needed
144
+ 4. Measure results and iterate for continuous improvement
145
+
146
+ ## Conclusion
147
+ {topic} offers significant opportunities for {target_audience.lower()} when approached strategically. The key points outlined above provide a solid foundation for moving forward with confidence and clarity.
148
 
149
+ ---
150
+ *This one-pager was generated to provide quick, actionable insights on {topic.lower()}.*"""
151
+
152
+ return template
153
+
154
+ # Create the Gradio interface
155
+ def create_interface():
156
+ with gr.Blocks(title="One-Pager Generator", theme=gr.themes.Soft()) as demo:
157
+ gr.Markdown("# πŸ“„ AI One-Pager Generator")
158
+ gr.Markdown("Generate professional one-page documents on any topic using AI!")
159
+
160
+ with gr.Row():
161
+ with gr.Column(scale=1):
162
+ topic_input = gr.Textbox(
163
+ label="Topic",
164
+ placeholder="e.g., Digital Marketing Strategy, Climate Change Solutions, etc.",
165
+ lines=2,
166
+ value="Artificial Intelligence in Healthcare"
167
+ )
168
+
169
+ audience_input = gr.Textbox(
170
+ label="Target Audience",
171
+ placeholder="e.g., Business executives, Students, General public, etc.",
172
+ lines=1,
173
+ value="Healthcare professionals"
174
+ )
175
+
176
+ keypoints_input = gr.Textbox(
177
+ label="Key Points to Cover",
178
+ placeholder="Enter main points separated by commas",
179
+ lines=4,
180
+ value="Machine learning applications, Data privacy, Cost-effectiveness, Implementation challenges"
181
+ )
182
+
183
+ tone_dropdown = gr.Dropdown(
184
+ choices=["Professional", "Casual", "Academic", "Persuasive", "Informative"],
185
+ label="Tone",
186
+ value="Professional"
187
+ )
188
+
189
+ length_dropdown = gr.Dropdown(
190
+ choices=["Short", "Medium", "Long"],
191
+ label="Length",
192
+ value="Medium"
193
+ )
194
+
195
+ generate_btn = gr.Button("πŸš€ Generate One-Pager", variant="primary")
196
+
197
+ with gr.Column(scale=2):
198
+ output_text = gr.Textbox(
199
+ label="Generated One-Pager",
200
+ lines=25,
201
+ max_lines=35,
202
+ show_copy_button=True,
203
+ placeholder="Your generated one-pager will appear here..."
204
+ )
205
+
206
+ with gr.Row():
207
+ gr.Markdown("""
208
+ ### πŸ’‘ Tips for Best Results:
209
+ - **Be specific** with your topic for more targeted content
210
+ - **Include 3-5 key points** separated by commas
211
+ - **Choose the right tone** for your intended audience
212
+ - **Use descriptive audience** details (e.g., "C-level executives" vs "executives")
213
+ """)
214
+
215
+ # Connect the generate button to the function
216
+ generate_btn.click(
217
+ fn=generate_onepager,
218
+ inputs=[topic_input, audience_input, keypoints_input, tone_dropdown, length_dropdown],
219
+ outputs=output_text
220
+ )
221
+
222
+ return demo
223
+
224
+ # Initialize model and launch
225
+ if __name__ == "__main__":
226
+ print("πŸš€ Starting One-Pager Generator...")
227
+ print("πŸ“₯ Loading AI model...")
228
+ initialize_model()
229
+ print("βœ… Model loaded! Launching interface...")
230
+
231
+ demo = create_interface()
232
+ demo.launch()