File size: 2,549 Bytes
eb5a3ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import requests
import os

from agent import generate_task_prompt

import pypdf
import docx2txt

def process_request(description, field, uploaded_files):
    files_data = []
    
    if uploaded_files:
        for file_path in uploaded_files:
            filename = os.path.basename(file_path)
            lower_name = filename.lower()
            try:
                if lower_name.endswith(".pdf"):
                    reader = pypdf.PdfReader(file_path)
                    content = "\n".join([page.extract_text() or "" for page in reader.pages])
                elif lower_name.endswith(".docx"):
                    content = docx2txt.process(file_path)
                else:
                    with open(file_path, "r", encoding="utf-8") as f:
                        content = f.read()
                files_data.append({"filename": filename, "content": content})
            except Exception as e:
                print(f"Skipping binary/unreadable file: {filename}")
                
    try:
        return generate_task_prompt(description, field, files_data)
    except Exception as e:
        return f"Error occurred: {str(e)}"

# Gradio Interface
with gr.Blocks(title="Task Prompting Tool") as demo:
    gr.Markdown("# 🚀 Developer Task Prompting Tool (RAG Enabled)")
    gr.Markdown("Generate high-quality, developer-ready prompts using advanced ChromaDB chunking for very large projects.")
    
    with gr.Row():
        with gr.Column(scale=2):
            field_input = gr.Dropdown(
                choices=["Backend", "Frontend", "Fullstack", "DevOps", "Data Science", "Mobile", "Other"], 
                label="Field / Application Area",
                value="Backend"
            )
            desc_input = gr.Textbox(
                label="Task Description", 
                placeholder="Describe what needs to be done...", 
                lines=5
            )
            file_input = gr.File(
                label="Upload Context Files (Code, MD, JSON, etc.)", 
                file_count="multiple"
            )
            submit_btn = gr.Button("Generate Prompt", variant="primary")
            
        with gr.Column(scale=3):
            output_text = gr.Textbox(
                label="Generated Task Prompt", 
                lines=15
            )
            
    submit_btn.click(
        fn=process_request,
        inputs=[desc_input, field_input, file_input],
        outputs=output_text
    )

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=7860)