File size: 6,282 Bytes
b6263d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import gradio as gr
from ai_wrapper import AIProjectAssistant
from typing import Tuple
import os
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

# Get API key from environment variable
API_KEY = os.getenv("OPENAI_API_KEY")
if not API_KEY:
    raise ValueError("No OpenAI API key found. Please set OPENAI_API_KEY environment variable.")

# Initialize AI Assistant
assistant = AIProjectAssistant(API_KEY)

# Updated project options focusing on Generative AI
PROJECT_OPTIONS = {
    "Text-to-Image Generation": "Create an AI system that generates images from text descriptions using models like DALL-E or Stable Diffusion",
    "GPT Chatbot Assistant": "Build a custom GPT-powered chatbot assistant for specific domain expertise",
    "AI Story Generator": "Develop a creative writing AI that generates stories based on prompts",
    "Voice Cloning AI": "Create a system that can clone and synthesize human voices",
    "AI Music Composer": "Build an AI system that composes original music in different styles",
    "Text-to-Video Generation": "Implement a system that creates short videos from text descriptions",
    "AI Code Generator": "Create a coding assistant that generates code from natural language descriptions",
    "AI Art Style Transfer": "Develop a system that applies artistic styles to images using AI",
    "AI Content Summarizer": "Build an AI that creates concise summaries of long-form content",
    "Virtual Avatar Creator": "Create an AI system that generates and animates virtual avatars"
}

# Custom CSS for better styling
CUSTOM_CSS = """

.container {

    max-width: 1200px;

    margin: auto;

    padding: 20px;

}

.title {

    text-align: center;

    color: #2a9d8f;

    padding: 20px;

    border-bottom: 3px solid #264653;

    margin-bottom: 30px;

}

.subtitle {

    color: #264653;

    text-align: center;

    font-style: italic;

}

.project-button {

    margin: 5px;

    border: 2px solid #2a9d8f;

    border-radius: 8px;

    background-color: #f8f9fa;

}

.project-button:hover {

    background-color: #2a9d8f;

    color: white;

}

.output-box {

    border: 2px solid #264653;

    border-radius: 10px;

    padding: 15px;

}

.sidebar {

    background-color: #f8f9fa;

    padding: 20px;

    border-radius: 10px;

    border: 2px solid #264653;

}

"""

def process_input(input_type: str, query: str) -> Tuple[str, str]:
    """Process user input and return AI response."""
    if not query.strip():
        return "", "Please enter a query"
    
    if input_type == "brainstorm":
        response = assistant.brainstorm_project(query)
    else:
        response = assistant.get_code_suggestion(query)
    
    if response["success"]:
        status = f"Success! Tokens used: {response.get('tokens_used', 'N/A')}"
        return response["content"], status
    else:
        return "", f"Error: {response.get('error', 'Unknown error occurred')}"

def handle_project_click(project_name: str) -> Tuple[str, str, str]:
    """Handle when a project option is clicked."""
    description = PROJECT_OPTIONS[project_name]
    response = assistant.brainstorm_project(description)
    
    if response["success"]:
        status = f"Success! Tokens used: {response.get('tokens_used', 'N/A')}"
        return "brainstorm", description, response["content"]
    else:
        return "brainstorm", description, f"Error: {response.get('error', 'Unknown error occurred')}"

# Create Gradio interface with custom theme
with gr.Blocks(css=CUSTOM_CSS, title="DDS AI Project Assistant") as interface:
    with gr.Column(elem_classes="container"):
        gr.HTML("""

            <div class="title">

                <h1>πŸ€– DDS AI Project Assistant πŸš€</h1>

                <p class="subtitle">Your Generative AI Project Development Companion</p>

            </div>

        """)
        
        with gr.Row():
            # Left sidebar with project options
            with gr.Column(scale=1, elem_classes="sidebar"):
                gr.HTML("""

                    <h3 style="text-align: center; color: #2a9d8f;">

                        🎯 Popular GenAI Projects

                    </h3>

                """)
                project_buttons = [
                    gr.Button(
                        name,
                        elem_classes="project-button"
                    ) for name in PROJECT_OPTIONS.keys()
                ]
            
            # Main content area
            with gr.Column(scale=3):
                input_type = gr.Radio(
                    choices=["brainstorm", "code"],
                    label="πŸ€” What kind of help do you need?",
                    value="brainstorm"
                )
                
                query = gr.Textbox(
                    label="πŸ’­ Enter your topic or code request",
                    placeholder="e.g., 'text-to-image generation' or 'implement stable diffusion'",
                    elem_classes="output-box"
                )
                
                submit_btn = gr.Button(
                    "πŸš€ Get AI Assistance",
                    elem_classes="project-button"
                )
                
                with gr.Column(elem_classes="output-box"):
                    output = gr.Textbox(
                        label="πŸ€– AI Response",
                        lines=10
                    )
                    status = gr.Textbox(
                        label="πŸ“Š Status"
                    )
        
        gr.HTML("""

            <div style="text-align: center; margin-top: 20px; padding: 10px; border-top: 2px solid #264653;">

                <p>Developed by DDS Team | Powered by OpenAI</p>

            </div>

        """)
    
    # Handle main submit button
    submit_btn.click(
        fn=process_input,
        inputs=[input_type, query],
        outputs=[output, status]
    )
    
    # Handle project option buttons
    for btn in project_buttons:
        btn.click(
            fn=handle_project_click,
            inputs=[btn],
            outputs=[input_type, query, output]
        )

if __name__ == "__main__":
    interface.launch()