Spaces:
Build error
Build error
Upload folder using huggingface_hub
Browse filesFiles changed (27)
- .docker/DockerfileAdded+20
- .gitignoreAdded+2
- .gradio/certificate.pemAdded+31
- README.md+4-9
- api/__init__pyAdded
- api/initiate_pipeline_call.pyAdded+34
- components/__init__.pyAdded
- components/bug_finding.pyAdded+8
- components/chat.pyAdded+13
- components/file_upload.pyAdded+10
- components/front_page.pyAdded+65
- components/interface.pyAdded+44
- components/model_selection.pyAdded+4
- components/patch_generation.pyAdded+8
- components/patch_geration.pyAdded
- components/patch_validation.pyAdded+8
- components/pattern_matching.pyAdded+8
- docker-compose.ymlAdded+14
- logo.pngAdded
- main.pyAdded+10
- requirements.txtAdded+75
- ui/FrontPage.pyAdded+99
- ui/__init__.pyAdded
- utils/convert_steps.pyAdded+4
- utils/interface_utils.pyAdded+105
- utils/process_steps.pyAdded+3
- utils/storage.pyAdded+11
1234567891011121314151617181920# Use an official Python imageFROM python:3.13
# Set the working directoryWORKDIR /app
# Copy only requirements first (for better caching)COPY requirements.txt .
# Install dependenciesRUN pip install --no-cache-dir -r requirements.txt
# Copy the rest of the application codeCOPY . .
# Expose the port Gradio runs onEXPOSE 7860
# Command to run the Gradio appCMD ["python", "interface.py"]12__pycache__models12345678910111213141516171819202122232425262728293031-----BEGIN CERTIFICATE-----MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAwTzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2VhcmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJuZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBYMTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0F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dwJx4nLCgdNbOhdjsnvzqvHu7UrTkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdCjNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVcoyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPAmRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57demyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=-----END CERTIFICATE-----123456789101112---title: Code Repair With LLMsemoji: 📊colorFrom: pinkcolorTo: redsdk: gradiosdk_version: 5.16.1app_file: app.pypinned: false---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference1234567---title: Code-Repair-With-LLMsapp_file: main.pysdk: gradiosdk_version: 5.5.0---frontend for code repair w llms
12345678910111213141516171819202122232425262728293031323334import requestsimport osimport mimetypes
API_URL = "http://localhost:8000/api/initiate_pipeline"
def initiate_pipeline_call(files, pipeline_steps): """ Initiate the pipeline with multiple files. Args: files: List of tuples containing file information (name, content, type) pipeline_steps: Integer representing selected pipeline steps """
file_data = [] for file in files: mime_type = mimetypes.guess_type(file.name)[0] or "application/octet-stream" # Ensure we send the actual file content with open(file.name, "rb") as f: file_data.append(("files", (file.name, f.read(), mime_type)))
try: response = requests.post( f"{API_URL}?pipeline_steps={pipeline_steps}", files=file_data ) response.raise_for_status() # Raise exception for bad status codes return response.json() except requests.exceptions.RequestException as e: return f"Error: {str(e)}"12345678import gradio as grfrom components.model_selection import create_model_selection_dropdown
def create_bug_finding_tab(choices): with gr.Column(): create_model_selection_dropdown(choices) gr.Textbox(label="Output", interactive=False) gr.Code(label="File Contents", language="python", interactive=False, elem_classes=["fixed-height"])12345678910111213import gradio as gr
def create_chat_controls(): with gr.Row(): with gr.Column(scale=10): msg = gr.Textbox(label="Prompt", placeholder="Enter prompt")
with gr.Row(): with gr.Column(min_width=0, scale=10): submit_button = gr.Button("Submit Prompt")
return msg, submit_button
12345678910import gradio as gr
def create_file_upload_section(): with gr.Row(equal_height=True): # Ensures both sections are the same height with gr.Column(scale=1): file_input = gr.File(label="Upload Codebase/Single File", file_types=[".py", ".java", ".c", ".cpp"]) with gr.Column(scale=3): file_content = gr.Code(label="File Contents", language="python", interactive=False, elem_classes=["fixed-height"]) return file_input, file_content1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465import gradio as grimport utils.interface_utils as iutils
from api.initiate_pipeline_call import initiate_pipeline_callfrom utils.convert_steps import convert_stepsfrom utils.storage import save_jwt_to_sessionfrom components.interface import create_interfacefrom components.model_selection import create_model_selection_dropdown
def handle_initiate_pipeline(files, selected_steps, initial_prompt): """Processes the file upload and initiates the pipeline.""" if not files: gr.Warning("Please upload a file/codebase.") return gr.update(visible=True), gr.update(visible=False) binary_steps = convert_steps(selected_steps)
# TODO: Do something with prompt response = initiate_pipeline_call(files, binary_steps) ''' Delete print below in production ''' print(response) save_jwt_to_session(response)
return gr.update(visible=False), gr.update(visible=True)
def create_full_ui(): """Creates the full UI with a front page and the main interface.""" with gr.Blocks(theme=iutils.custom_theme(), css="style.css") as app: # TODO: Replace with actual choices choices = ["ChatGPT", "Claude"]
# Front Page UI with gr.Column(visible=True) as front_page: gr.Markdown("# Welcome to Code Repair with LLMs!") gr.Markdown("## Upload your files/codebase. All steps of the pipeline will be executed on the initial run.")
file_input = gr.Files( label="Upload Multiple Files / Codebase", file_types=[".py", ".java", ".c", ".cpp"] ) gr.Markdown("Python, Java, C++, and .zip files accepted.")
steps = ["Bug Finding", "Pattern Matching", "Patch Generation", "Patch Validation"] checkboxes = gr.CheckboxGroup(steps, label="Select Desired Steps", value=steps, interactive=False)
create_model_selection_dropdown(choices=choices)
msg = gr.Textbox(label="Prompt", placeholder="Enter prompt (Optional)") initiate_button = gr.Button("Initiate Pipeline")
# Main Interface UI (Initially Hidden) with gr.Row(visible=False) as main_interface: interface = create_interface()
# Button click should happen inside the context initiate_button.click( fn=handle_initiate_pipeline, inputs=[file_input, checkboxes, msg], outputs=[front_page, main_interface] )
return app1234567891011121314151617181920212223242526272829303132333435363738394041424344import gradio as grimport osimport utils.interface_utils as iutilsfrom components.chat import create_chat_controlsfrom components.bug_finding import create_bug_finding_tabfrom components.pattern_matching import create_pattern_matching_tabfrom components.patch_generation import create_patch_generation_tabfrom components.patch_validation import create_patch_validation_tabfrom components.file_upload import create_file_upload_section
def create_interface(): # TODO: Replace with actual choices choices = ["ChatGPT", "Claude"]
with gr.Blocks(theme=iutils.custom_theme(), css=iutils.custom_css()) as interface: with gr.Column(): # Header with Logo with gr.Row(): gr.Markdown("# Code Repair with LLMs") gr.Markdown("") # Filler to push logo to the right gr.Image("logo.png", label="Logo", show_download_button=False, show_fullscreen_button=False, show_label=False, height=250, width=450, container=False)
# Tabs for Different Features with gr.Tab("Chat"): create_bug_finding_tab(choices)
with gr.Tab("Bug Finding"): create_bug_finding_tab(choices)
with gr.Tab("Pattern Matching"): create_pattern_matching_tab(choices)
with gr.Tab("Patch Generation"): create_patch_generation_tab(choices)
with gr.Tab("Patch Validation"): create_patch_validation_tab(choices)
# Chatbot Always at the Bottom with gr.Column(): chatbot = gr.Chatbot(value=None, type="messages", show_label=True, show_share_button=False) create_chat_controls()
return interface1234import gradio as gr
def create_model_selection_dropdown(choices): return gr.Dropdown(label="Model Selection", choices=choices, interactive=True)12345678import gradio as grfrom components.model_selection import create_model_selection_dropdown
def create_patch_generation_tab(choices): with gr.Column(): create_model_selection_dropdown(choices) gr.Textbox(label="Output", interactive=False) gr.Code(label="File Contents", language="python", interactive=False, elem_classes=["fixed-height"])12345678import gradio as grfrom components.model_selection import create_model_selection_dropdown
def create_patch_validation_tab(choices): with gr.Column(): create_model_selection_dropdown(choices) gr.Textbox(label="Output", interactive=False) gr.Code(label="File Contents", language="python", interactive=False, elem_classes=["fixed-height"])12345678import gradio as grfrom components.model_selection import create_model_selection_dropdown
def create_pattern_matching_tab(choices): with gr.Column(): create_model_selection_dropdown(choices) gr.Textbox(label="Output", interactive=False) gr.Code(label="File Contents", language="python", interactive=False, elem_classes=["fixed-height"])1234567891011121314version: "3.8"
services: gradio_app: build: context: . # Use the root as context dockerfile: .docker/Dockerfile # Specify the Dockerfile inside .docker ports: - "7860:7860" volumes: - .:/app environment: - PYTHONUNBUFFERED=1 restart: unless-stopped12345678910import gradio as grfrom components.front_page import create_full_ui
# Create the UIapp = create_full_ui()
# Launch the appif __name__ == "__main__": app.launch(share=True, show_api=False)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475aiofiles==23.2.1annotated-types==0.7.0anyio==4.8.0audioop-lts==0.2.1certifi==2025.1.31cffi==1.17.1charset-normalizer==3.4.1click==8.1.8colorama==0.4.6contourpy==1.3.1cycler==0.12.1fastapi==0.115.8ffmpy==0.5.0filelock==3.17.0fonttools==4.56.0fsspec==2025.2.0gevent==24.11.1gradio==5.15.0gradio_client==1.7.0greenlet==3.1.1h11==0.14.0httpcore==1.0.7httpx==0.28.1huggingface-hub==0.28.1idna==3.10Jinja2==3.1.5joblib==1.4.2kiwisolver==1.4.8markdown-it-py==3.0.0MarkupSafe==2.1.5matplotlib==3.10.0mdurl==0.1.2mplfinance==0.12.10b0numpy==2.2.2nvdlib==0.7.9orjson==3.10.15packaging==24.2pandas==2.2.3pillow==11.1.0pycparser==2.22pydantic==2.10.6pydantic_core==2.27.2pydub==0.25.1Pygments==2.19.1pyparsing==3.2.1python-dateutil==2.9.0.post0python-multipart==0.0.20pytz==2025.1PyYAML==6.0.2requests==2.32.3rich==13.9.4ruff==0.9.6safehttpx==0.1.6scikit-learn==1.6.1scipy==1.15.1seaborn==0.13.2semantic-version==2.10.0setuptools==75.8.0shellingham==1.5.4six==1.17.0sniffio==1.3.1starlette==0.45.3threadpoolctl==3.5.0tomlkit==0.13.2tqdm==4.67.1typer==0.15.1typing_extensions==4.12.2tzdata==2025.1urllib3==2.3.0uvicorn==0.34.0websocket-client==1.8.0websockets==14.2zope.event==5.0zope.interface==7.2websocket-client123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899import gradioimport osimport sys
sys.path.insert(0, os.path.abspath("./"))
from source.api_calls.initiate_pipeline_call import initiate_pipeline_callfrom utils.process_steps import process_steps
pipeline_steps = 21
class FrontPage: def __init__(self): with gradio.Blocks(css=self.custom_css()) as self.page: gradio.Markdown("# Code Repair with LLMs") gradio.Markdown("Upload a Python, Java, C, or C++ file for processing") with gradio.Row(): file_input = gradio.File(label="Upload Code File", file_types=[".py", ".java", ".c", ".cpp"]) language_input = gradio.Dropdown(choices=["Python", "Java", "C", "C++"], label="Language") file_content = gradio.Code(label="File Contents", language="python", interactive=False, elem_classes=["fixed-height"]) process_button = gradio.Button("Process")
with gradio.Row(): stage1 = gradio.Textbox(label="Fault Localization", value="Pending", interactive=False, elem_classes=["stage-box"]) stage2 = gradio.Textbox(label="Pattern Matching", value="Pending", interactive=False, elem_classes=["stage-box"]) stage3 = gradio.Textbox(label="Patch Generation", value="Pending", interactive=False, elem_classes=["stage-box"]) stage4 = gradio.Textbox(label="Patch Validation", value="Pending", interactive=False, elem_classes=["stage-box"])
output = gradio.Code(label="Processed Output", language="python", elem_classes=["fixed-height"])
pipeline_steps_input = gradio.Number(value=pipeline_steps, label="Pipeline Steps")
file_input.change(fn=self.display_file_content, inputs=[file_input], outputs=[file_content]) process_button.click(fn=self.initiate_pipeline, inputs=[file_input, language_input, pipeline_steps_input], outputs=[])
def custom_css(self): return """ .fixed-height { height: 300px !important; overflow-y: auto !important; } .stage-box { text-align: center !important; font-weight: bold !important; } """
def display_file_content(self, file): if file is None: return "No file uploaded yet." try: if isinstance(file, str): with open(file, 'r') as f: return f.read() elif hasattr(file, 'name'): return file.name elif hasattr(file, 'read'): return file.read().decode('utf-8') else: return str(file) except Exception as e: return f"An error occurred while reading the file: {str(e)}"
def initiate_pipeline(self, file_input, language_input, pipeline_steps): if file_input is None or (isinstance(file_input, list) and len(file_input) == 0): return "No file uploaded."
self.process_file(file_input, language_input) # If file_input is a list, take the first file if isinstance(file_input, list): file_input = file_input[0] print(f"Processing file: {file_input}") return initiate_pipeline_call(file_input, pipeline_steps) def process_file(self, file, language): if file is None: return "Skipped", "Skipped", "Skipped", "Skipped", "Please upload a file." try: content = self.display_file_content(file) stage1_result = "Complete" stage2_result = "Complete" stage3_result = "Complete" stage4_result = "Complete" processed_content = self.process_content(content, language) return stage1_result, stage2_result, stage3_result, stage4_result, processed_content except Exception as e: return "Error", "Error", "Error", "Error", f"An error occurred: {str(e)}"
def process_content(self, content, language): # This is where you would implement your actual processing logic # For now, we'll just return the file content with a message return f"Processing {language} code:\n\n{content}\n\nProcessing complete."1234def convert_steps(selected_steps): """Converts selected steps into a binary value (bitmask).""" all_steps = ["Bug Finding", "Pattern Matching", "Patch Generation", "Patch Validation"] return sum(1 << i for i, step in enumerate(all_steps) if step in selected_steps)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105# event handlers
import gradio as gr
def custom_theme(): # Gradio UI styling return gr.themes.Ocean( primary_hue=gr.themes.Color(c100="#fef9c3", c200="#fef08a", c300="#fde047", c400="#facc15", c50="#fefce8", c500="#eab308", c600="#ca8a04", c700="#a16207", c800="#854d0e", c900="#713f12", c950="#BA9B37"), secondary_hue="zinc", radius_size="lg", ).set( background_fill_primary='*neutral_900', background_fill_secondary='*neutral_700', body_background_fill='*secondary_900', body_text_color='*neutral_100', body_text_color_subdued='*neutral_400', border_color_accent='*neutral_900', button_secondary_background_fill='linear-gradient(120deg, *secondary_900 0%, *primary_400 50%, *primary_700 100%)', button_secondary_background_fill_hover='linear-gradient(120deg, *secondary_900 0%, *primary_400 50%, *primary_700 100%)', checkbox_label_background_fill_selected="linear-gradient(120deg, *secondary_900 0%, *primary_400 50%, *primary_700 100%)", code_background_fill='*neutral_950', color_accent_soft='*primary_950', input_background_fill='*neutral_700', table_odd_background_fill='*neutral_700' )
def custom_css(): return """ .fixed-height { height: 300px !important; overflow-y: auto !important; }
.stage-box { text-align: center !important; font-weight: bold !important; }
.title { text-align: center; font-size: 2rem; font-weight: bold; }
.subtitle { text-align: center; font-size: 1.2rem; }
.big-checkboxes label { font-size: 1.5rem; display: block; text-align: center; }
.big-button { font-size: 1.5rem; padding: 10px 20px; display: block; margin: 0 auto; }
"""
def display_file_content(file): if file is None: return "No file uploaded yet." try: if isinstance(file, str): with open(file, 'r') as f: return f.read() elif hasattr(file, 'name'): return file.name elif hasattr(file, 'read'): return file.read().decode('utf-8') else: return str(file) except Exception as e: return f"An error occurred while reading the file: {str(e)}"
def process_file(file, language): if file is None: return "Skipped", "Skipped", "Skipped", "Skipped", "Please upload a file." try: content = display_file_content(file) stage1_result = "Complete" stage2_result = "Complete" stage3_result = "Complete" stage4_result = "Complete" processed_content = process_content(content, language) return stage1_result, stage2_result, stage3_result, stage4_result, processed_content except Exception as e: return "Error", "Error", "Error", "Error", f"An error occurred: {str(e)}"
def process_content(content, language): # This is where you would implement your actual processing logic # For now, we'll just return the file content with a message return f"Processing {language} code:\n\n{content}\n\nProcessing complete."123
def process_steps(): return1234567891011import gradio as gr
def save_jwt_to_session(response): """Extracts session_token and session_id from API response and saves them in Gradio State.""" session_token = response.get("session_token") session_id = response.get("session_id")
if session_token and session_id: return gr.update(value=session_token), gr.update(value=session_id) return gr.update(), gr.update().docker/DockerfileAdded+20
.gitignoreAdded+2
.gradio/certificate.pemAdded+31
README.md+4-9
api/__init__pyAdded
api/initiate_pipeline_call.pyAdded+34
components/__init__.pyAdded
components/bug_finding.pyAdded+8
components/chat.pyAdded+13
components/file_upload.pyAdded+10
components/front_page.pyAdded+65
components/interface.pyAdded+44
components/model_selection.pyAdded+4
components/patch_generation.pyAdded+8
components/patch_geration.pyAdded
components/patch_validation.pyAdded+8
components/pattern_matching.pyAdded+8
docker-compose.ymlAdded+14
logo.pngAdded

main.pyAdded+10
requirements.txtAdded+75
ui/FrontPage.pyAdded+99
ui/__init__.pyAdded
utils/convert_steps.pyAdded+4
utils/interface_utils.pyAdded+105
utils/process_steps.pyAdded+3
utils/storage.pyAdded+11