Vinitrajputt commited on
Commit
f5ccba2
1 Parent(s): 67b6e62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -29
app.py CHANGED
@@ -1,43 +1,32 @@
1
  import gradio as gr
 
 
2
 
3
- def code_generation(code):
4
- """
5
- Function to generate code based on user input.
6
- This function will be called when the user interacts with the app.
7
- """
8
- # You can specify the programming language here
9
- # based on the user's choice or default to a specific language.
10
- language = "Python" # Example: defaulting to Python
11
-
12
- # Your code generation logic goes here
13
- generated_code = generate_code(code, language) # Replace with your code generation function
14
-
15
- return generated_code
16
 
17
- def generate_code(code, language):
18
- """
19
- Placeholder function for code generation logic.
20
- Replace this with your actual code generation implementation.
21
- """
22
- generated_code = f"Generated {language} code: {code}"
23
  return generated_code
24
 
25
- # Define the Gradio interface
26
- inputs = gr.inputs.Textbox(lines=10, label="Enter your code")
27
- outputs = gr.outputs.Textbox(label="Generated code")
28
-
29
- interface = gr.Interface(
30
  fn=code_generation,
31
- inputs=inputs,
32
- outputs=outputs,
33
  title="Gardio App",
34
  description="An app that generates code based on user input.",
35
  examples=[
36
  ["Example input code snippet"],
37
  ["Another example input code snippet"],
38
  ],
39
- allow_screenshot=True # Enable screenshot functionality for sharing
40
  )
41
 
42
- if __name__ == "__main__":
43
- interface.launch()
 
1
  import gradio as gr
2
+ import torch
3
+ from transformers import GPT2LMHeadModel, GPT2Tokenizer
4
 
5
+ # Load the model and tokenizer
6
+ model_name = "abacaj/Replit-v2-CodeInstruct-3B-ggml"
7
+ model = GPT2LMHeadModel.from_pretrained(model_name)
8
+ tokenizer = GPT2Tokenizer.from_pretrained(model_name)
 
 
 
 
 
 
 
 
 
9
 
10
+ # Define the code generation function
11
+ def code_generation(code):
12
+ inputs = tokenizer.encode(code, return_tensors="pt")
13
+ outputs = model.generate(inputs, max_length=100, num_return_sequences=1)
14
+ generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
 
15
  return generated_code
16
 
17
+ # Create the Gradio interface
18
+ iface = gr.Interface(
 
 
 
19
  fn=code_generation,
20
+ inputs=gr.inputs.Textbox(lines=10, label="Enter your code"),
21
+ outputs=gr.outputs.Textbox(label="Generated code"),
22
  title="Gardio App",
23
  description="An app that generates code based on user input.",
24
  examples=[
25
  ["Example input code snippet"],
26
  ["Another example input code snippet"],
27
  ],
28
+ allow_screenshot=True
29
  )
30
 
31
+ # Launch the interface
32
+ iface.launch()