CoolFace
Apppublic

Oranblock/Shells

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py48 linesDownload Raw Back to root
1import gradio as gr2from transformers import AutoTokenizer, AutoModelForCausalLM3 4# Load a Hugging Face model (e.g., GPT-Neo)5model_name = "EleutherAI/gpt-neo-1.3B"  # Choose a model from Hugging Face6tokenizer = AutoTokenizer.from_pretrained(model_name)7model = AutoModelForCausalLM.from_pretrained(model_name)8 9# Function to analyze and fix shell scripts10def analyze_and_fix_shell_script(script_content):11    # Create the prompt for GPT-Neo to analyze and fix the shell script12    prompt = f"""13    I have the following shell script. Please identify any errors, inefficiencies, or improvements that can be made. Provide an explanation of each issue and then suggest an improved version of the script:14    15    Script:16    {script_content}17    18    Please return the improved script and highlight the changes you made.19    """20    21    inputs = tokenizer(prompt, return_tensors="pt", max_length=512, truncation=True)22    outputs = model.generate(**inputs, max_length=1024, num_return_sequences=1)23    return tokenizer.decode(outputs[0], skip_special_tokens=True)24 25# Gradio interface to upload shell script and process26def upload_and_fix(file):27    # Handle both string and byte file formats28    script_content = file if isinstance(file, str) else file.decode("utf-8")29    30    # Call the GPT model to analyze and fix the shell script31    fixed_script = analyze_and_fix_shell_script(script_content)32    33    return fixed_script34 35# Create a Gradio interface36with gr.Blocks() as demo:37    with gr.Row():38        with gr.Column():39            gr.Markdown("## Upload Shell Script for Analysis and Fixing")40            file_input = gr.File(label="Upload Shell Script (.sh)")41            output_text = gr.Textbox(label="Fixed Shell Script", lines=20)42            submit_btn = gr.Button("Analyze and Fix")43        44        # Define the button action45        submit_btn.click(upload_and_fix, inputs=file_input, outputs=output_text)46    47    # Launch the app48    demo.launch()