Spaces:
Sleeping
Sleeping
| 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) | |