Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
|
4 |
+
# Load a Hugging Face model (e.g., GPT-Neo)
|
5 |
+
model_name = "EleutherAI/gpt-neo-1.3B" # Choose a model from Hugging Face
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# Function to analyze and fix shell scripts
|
10 |
+
def analyze_and_fix_shell_script(script_content):
|
11 |
+
# Create the prompt for GPT-Neo to analyze and fix the shell script
|
12 |
+
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 process
|
26 |
+
def upload_and_fix(file):
|
27 |
+
script_content = file.read().decode("utf-8")
|
28 |
+
fixed_script = analyze_and_fix_shell_script(script_content)
|
29 |
+
return fixed_script
|
30 |
+
|
31 |
+
# Create a Gradio interface
|
32 |
+
with gr.Blocks() as demo:
|
33 |
+
with gr.Row():
|
34 |
+
with gr.Column():
|
35 |
+
gr.Markdown("## Upload Shell Script for Analysis and Fixing")
|
36 |
+
file_input = gr.File(label="Upload Shell Script (.sh)")
|
37 |
+
output_text = gr.Textbox(label="Fixed Shell Script", lines=20)
|
38 |
+
submit_btn = gr.Button("Analyze and Fix")
|
39 |
+
|
40 |
+
# Define the button action
|
41 |
+
submit_btn.click(upload_and_fix, inputs=file_input, outputs=output_text)
|
42 |
+
|
43 |
+
# Launch the app
|
44 |
+
demo.launch()
|