File size: 4,565 Bytes
ccbdd61
 
c101c53
24371db
 
 
 
 
 
 
ccbdd61
 
 
 
 
77e744f
ccbdd61
3d87c18
 
ccbdd61
c101c53
3d87c18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccbdd61
3d87c18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b7d78a
 
c101c53
 
ccbdd61
3d87c18
 
 
 
ccbdd61
 
 
24371db
3d87c18
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
from utils import TEMP_DIR, message_dict
import gradio as gr
import templates.data_file as data_file, templates.sql_db as sql_db

import os
from getpass import getpass
from dotenv import load_dotenv

load_dotenv()

def delete_db(req: gr.Request):
    import shutil
    dir_path = TEMP_DIR / str(req.session_hash)
    if os.path.exists(dir_path):
        shutil.rmtree(dir_path)
        message_dict[req.session_hash] = {}

if "OPENAI_API_KEY" not in os.environ:
    os.environ["OPENAI_API_KEY"] = getpass("Enter OpenAI API key:")

css= ".file_marker .large{min-height:50px !important;} .padding{padding:0;} .description_component{overflow:visible !important;}"
head = """<meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Virtual Data Analyst</title>

    <!-- Tailwind CSS -->

    <script src="https://cdn.tailwindcss.com"></script>

    <!-- Google Fonts -->

    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">

    <!-- Font Awesome -->

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">

    <!-- Custom Styles -->

    <link rel="stylesheet" href="/gradio_api/file=assets/styles.css">

    """

theme = gr.themes.Base(primary_hue="sky", secondary_hue="slate",font=[gr.themes.GoogleFont("Inter"), "Inter", "sans-serif"]).set(
    button_primary_background_fill="#3B82F6",
    button_secondary_background_fill="#6B7280",
)

from pathlib import Path
gr.set_static_paths(paths=[Path.cwd().absolute()/"assets"])

with gr.Blocks(theme=theme, css=css, head=head, delete_cache=(3600,3600)) as demo:
    header = gr.HTML("""

                        <!-- Header -->

                        <header class="max-w-4xl mx-auto mb-12 text-center">

                            <h1 class="text-4xl font-bold text-gray-900 mb-4">Virtual Data Analyst</h1>

                            <p class="text-lg text-gray-600 mb-6">

                                A powerful tool for data analysis, visualizations, and insights

                            </p>

                        </header>

                        <!-- Main Content -->

                        <main class="max-w-4xl mx-auto">

                            <!-- Features Preview -->

                            <div class="mt-12 grid md:grid-cols-3 gap-6" style="margin-bottom:3px !important;">

                                <div class="feature-card bg-white p-6 rounded-lg shadow-md">

                                    <i class="feature-icon fas fa-chart-line text-primary text-2xl mb-4"></i>

                                    <h3 class="font-semibold text-gray-800 mb-2">Advanced Analytics</h3>

                                    <p class="text-gray-600 text-sm">Run SQL queries, perform regressions, and analyze results with ease</p>

                                </div>

                                <div class="feature-card bg-white p-6 rounded-lg shadow-md">

                                    <i class="feature-icon fas fa-chart-pie text-primary text-2xl mb-4"></i>

                                    <h3 class="font-semibold text-gray-800 mb-2">Rich Visualizations</h3>

                                    <p class="text-gray-600 text-sm">Create scatter plots, line charts, pie charts, and more</p>

                                </div>

                                <div class="feature-card bg-white p-6 rounded-lg shadow-md">

                                    <i class="feature-icon fas fa-magic text-primary text-2xl mb-4"></i>

                                    <h3 class="font-semibold text-gray-800 mb-2">Automated Insights</h3>

                                    <p class="text-gray-600 text-sm">Get instant insights and recommendations for your data</p>

                                </div>

                            </div>

                        </main>""")
    with gr.Tab("Data File"):    
        data_file.demo.render()
    with gr.Tab("SQL Database"):
        sql_db.demo.render()

    footer = gr.HTML("""<!-- Footer -->

        <footer class="max-w-4xl mx-auto mt-12 text-center text-gray-500 text-sm">

            <p>This application is under active development. For bugs or feedback, please open a discussion in the community tab.</p>

        </footer>""")

    demo.unload(delete_db)

## Uncomment the line below to launch the chat app with UI
demo.launch(debug=True, allowed_paths=["temp/","assets/"])