File size: 4,639 Bytes
6c36389
 
 
 
 
e1e8a7c
6c36389
085e4f6
 
 
 
 
6c36389
085e4f6
 
e1e8a7c
085e4f6
e1e8a7c
 
6c36389
085e4f6
 
6c36389
 
085e4f6
 
 
6c36389
e1e8a7c
 
 
1d1990f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406abdb
 
 
 
 
1d1990f
085e4f6
 
 
 
 
e1e8a7c
 
 
 
 
 
 
1d1990f
e1e8a7c
 
 
 
406abdb
 
 
085e4f6
 
6c36389
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Python Code Parser & Program Retrieval</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://unpkg.com/[email protected]"></script>
    <style>
        .table-container { overflow-x: auto; }
        pre { white-space: pre-wrap; word-wrap: break-word; }
    </style>
</head>
<body class="bg-gray-900 text-gray-200 min-h-screen p-8 font-sans">
    <div class="max-w-7xl mx-auto bg-gray-800 p-6 rounded-xl shadow-2xl">
        <h1 class="text-3xl font-bold text-blue-400 mb-6">Python Code Parser & Program Retrieval</h1>

        <!-- Parsing Form -->
        <form hx-post="/" hx-target="#results" hx-swap="innerHTML" class="space-y-6 mb-8">
            <div>
                <label class="block text-sm font-medium text-gray-300 mb-2">Upload a Python File</label>
                <input type="file" name="file" accept=".py" class="w-full p-2 border rounded-lg bg-gray-700 text-gray-200">
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-300 mb-2">Or Paste Your Code</label>
                <textarea name="code" rows="6" class="w-full p-2 border rounded-lg bg-gray-700 text-gray-200" placeholder="Paste Python code here...">{{ code_input or '' }}</textarea>
                <input type="text" name="filename" class="mt-2 w-full p-2 border rounded-lg bg-gray-700 text-gray-200" placeholder="Enter filename (e.g., script.py)" value="{{ filename or '' }}">
            </div>
            <button type="submit" class="w-full bg-blue-500 text-white p-2 rounded-lg hover:bg-blue-600 transition">Parse & Store</button>
        </form>

        <!-- Query Forms -->
        <div class="space-y-4 mb-8">
            <form hx-post="/" hx-target="#results" hx-swap="innerHTML" class="space-y-4">
                <div>
                    <label class="block text-sm font-medium text-gray-300 mb-2">Query Programs by Operations (e.g., function,assignment,return)</label>
                    <input type="text" name="query_ops" class="w-full p-2 border rounded-lg bg-gray-700 text-gray-200" placeholder="Enter operations (comma-separated)">
                </div>
                <button type="submit" class="w-full bg-green-500 text-white p-2 rounded-lg hover:bg-green-600 transition">Find Programs by Operations</button>
            </form>

            <form hx-post="/" hx-target="#results" hx-swap="innerHTML" class="space-y-4">
                <div>
                    <label class="block text-sm font-medium text-gray-300 mb-2">Query Programs by Description (e.g., "function that adds numbers")</label>
                    <input type="text" name="semantic_query" class="w-full p-2 border rounded-lg bg-gray-700 text-gray-200" placeholder="Enter description">
                </div>
                <button type="submit" class="w-full bg-purple-500 text-white p-2 rounded-lg hover:bg-purple-600 transition">Find Programs by Description</button>
            </form>

            <!-- New Button to Process Hugging Face Dataset -->
            <form hx-post="/" hx-target="#results" hx-swap="innerHTML" class="space-y-4">
                <button type="submit" name="process_hf" value="true" class="w-full bg-orange-500 text-white p-2 rounded-lg hover:bg-orange-600 transition">Process Hugging Face Dataset</button>
            </form>
        </div>

        <!-- Results Section -->
        <div id="results" class="mt-8">
            {% if parts %}
                {% include 'results_partial.html' %}
            {% elif query_results %}
                <h2 class="text-2xl font-bold text-blue-400 mb-4">Matching Programs</h2>
                <div class="space-y-4">
                    {% for result in query_results %}
                    <div class="bg-gray-700 p-4 rounded-lg">
                        <h3 class="text-lg font-semibold text-blue-300">Program ID: {{ result.id }}</h3>
                        <p class="text-gray-200">Similarity: {{ result.similarity | round(3) }}</p>
                        <p class="text-gray-300">Description Tokens: {{ result.description }}</p>
                        <pre class="bg-gray-800 p-2 rounded mt-2 text-gray-300">{{ result.code }}</pre>
                    </div>
                    {% endfor %}
                </div>
            {% elif message %}
                <h2 class="text-2xl font-bold text-blue-400 mb-4">Status</h2>
                <p class="text-gray-200">{{ message }}</p>
            {% endif %}
        </div>
    </div>
</body>
</html>