3Stark123 commited on
Commit
42129d2
Β·
verified Β·
1 Parent(s): 2c9d9dc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +135 -0
app.py ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import os
4
+ from src.text_processor import TextProcessor
5
+ from src.gemini_client import GeminiClient
6
+ from src.template_manager import TemplateManager
7
+ from src.image_generator import ImageGenerator
8
+
9
+ # Initialize components
10
+ text_processor = TextProcessor()
11
+ gemini_client = GeminiClient()
12
+ template_manager = TemplateManager()
13
+ image_generator = ImageGenerator()
14
+
15
+ def generate_infographic(text, template_style, color_scheme, layout_type):
16
+ """Main function to generate infographic"""
17
+ try:
18
+ # Step 1: Process and analyze text
19
+ processed_text = text_processor.analyze(text)
20
+
21
+ # Step 2: Get AI insights from Gemini
22
+ ai_insights = gemini_client.get_insights(processed_text)
23
+
24
+ # Step 3: Apply template and styling
25
+ styled_content = template_manager.apply_template(
26
+ ai_insights, template_style, color_scheme, layout_type
27
+ )
28
+
29
+ # Step 4: Generate final image
30
+ infographic_path = image_generator.create_infographic(styled_content)
31
+
32
+ return infographic_path, "βœ… Infographic generated successfully!"
33
+
34
+ except Exception as e:
35
+ return None, f"❌ Error: {str(e)}"
36
+
37
+ # Create Gradio Interface
38
+ def create_interface():
39
+ with gr.Blocks(
40
+ theme=gr.themes.Soft(),
41
+ title="AI Infographic Generator",
42
+ css="""
43
+ .gradio-container {
44
+ max-width: 1200px !important;
45
+ margin: auto !important;
46
+ }
47
+ """
48
+ ) as app:
49
+
50
+ gr.Markdown("# 🎨 AI Infographic Generator")
51
+ gr.Markdown("Transform your text into beautiful infographics with AI!")
52
+
53
+ with gr.Row():
54
+ with gr.Column(scale=1):
55
+ # Input Section
56
+ gr.Markdown("## πŸ“ Input")
57
+ text_input = gr.Textbox(
58
+ label="Your Content",
59
+ placeholder="Paste your text here...",
60
+ lines=8,
61
+ max_lines=15
62
+ )
63
+
64
+ # Customization Options
65
+ gr.Markdown("## 🎨 Customize")
66
+ template_choice = gr.Dropdown(
67
+ choices=["Modern", "Minimalist", "Corporate", "Creative", "Academic"],
68
+ value="Modern",
69
+ label="Template Style"
70
+ )
71
+
72
+ color_scheme = gr.ColorPicker(
73
+ label="Primary Color",
74
+ value="#3498db"
75
+ )
76
+
77
+ layout_type = gr.Radio(
78
+ choices=["Vertical", "Horizontal", "Grid", "Flow"],
79
+ value="Vertical",
80
+ label="Layout Type"
81
+ )
82
+
83
+ generate_btn = gr.Button(
84
+ "πŸš€ Generate Infographic",
85
+ variant="primary",
86
+ size="lg"
87
+ )
88
+
89
+ with gr.Column(scale=1):
90
+ # Output Section
91
+ gr.Markdown("## πŸ–ΌοΈ Generated Infographic")
92
+ output_image = gr.Image(
93
+ label="Your Infographic",
94
+ show_label=False,
95
+ height=600
96
+ )
97
+
98
+ status_output = gr.Textbox(
99
+ label="Status",
100
+ interactive=False
101
+ )
102
+
103
+ # Download Section
104
+ download_file = gr.File(
105
+ label="Download High Resolution",
106
+ visible=False
107
+ )
108
+
109
+ # Examples Section
110
+ gr.Markdown("## πŸ“š Examples")
111
+ gr.Examples(
112
+ examples=[
113
+ ["Artificial Intelligence is transforming industries worldwide. Machine learning enables computers to learn from data without explicit programming. Deep learning uses neural networks to solve complex problems.", "Modern", "#3498db", "Vertical"],
114
+ ["Climate change is a global challenge requiring immediate action. Rising temperatures affect ecosystems, weather patterns, and human societies.", "Corporate", "#27ae60", "Horizontal"]
115
+ ],
116
+ inputs=[text_input, template_choice, color_scheme, layout_type]
117
+ )
118
+
119
+ # Event Handlers
120
+ generate_btn.click(
121
+ fn=generate_infographic,
122
+ inputs=[text_input, template_choice, color_scheme, layout_type],
123
+ outputs=[output_image, status_output]
124
+ )
125
+
126
+ return app
127
+
128
+ # Launch the app
129
+ if __name__ == "__main__":
130
+ app = create_interface()
131
+ app.launch(
132
+ share=False, # Set to True for temporary public link
133
+ server_name="0.0.0.0",
134
+ server_port=7860
135
+ )