acecalisto3 commited on
Commit
c43dc09
1 Parent(s): eeb235a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -9
app.py CHANGED
@@ -1,18 +1,33 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Assuming you have access to OpenAI's API and Codex
5
- # Replace 'your_api_key' with your actual OpenAI API key
6
- code_completion = pipeline("text-generation", model="code-davinci-002", temperature=0.7, max_length=50, num_return_sequences=1, api_key='your_api_key')
 
 
7
 
8
- def generate_code(input_code):
9
- return code_completion(input_code, max_length=50, num_return_sequences=1)[0]['generated_text']
 
 
 
 
 
 
 
 
 
 
10
 
 
11
  iface = gr.Interface(
12
- fn=generate_code,
13
- inputs=gr.inputs.Textbox(label="Enter your code snippet"),
14
- outputs=gr.outputs.Textbox(label="Generated Code"),
15
- title="Code Completion Assistant"
 
16
  )
17
 
 
18
  iface.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load the text generation pipeline
5
+ pipe = pipeline(
6
+ "text-generation",
7
+ model="MaziyarPanahi/BASH-Coder-Mistral-7B-Mistral-7B-Instruct-v0.2-slerp-GGUF"
8
+ )
9
 
10
+ def generate_bash_code(prompt):
11
+ """Generates BASH code using the Mistral-7B pipeline."""
12
+ sequences = pipe(
13
+ prompt,
14
+ max_length=200,
15
+ num_return_sequences=1,
16
+ do_sample=True, # Enable sampling for more creative output
17
+ top_k=50, # Explore a wider range of vocabulary
18
+ top_p=0.95, # Control the probability distribution of tokens
19
+ temperature=0.8 # Adjust temperature for creativity
20
+ )
21
+ return sequences[0]['generated_text']
22
 
23
+ # Create the Gradio interface
24
  iface = gr.Interface(
25
+ fn=generate_bash_code,
26
+ inputs=gr.Textbox(lines=5, label="Describe what you want your BASH script to do"),
27
+ outputs=gr.Code(language="bash", label="Generated BASH Code"),
28
+ title="BASH Coder",
29
+ description="Generate BASH scripts using a Mistral-7B model.",
30
  )
31
 
32
+ # Launch the interface
33
  iface.launch()