yukimama commited on
Commit
bbfa009
·
verified ·
1 Parent(s): 7500f3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -1,4 +1,5 @@
1
  from transformers import GPT2LMHeadModel, GPT2Tokenizer
 
2
 
3
  # Load the pre-trained GPT2 model and tokenizer
4
  model = GPT2LMHeadModel.from_pretrained("gpt2")
@@ -29,7 +30,16 @@ def generate_code(prompt, max_length=200):
29
 
30
  return code
31
 
32
- # Example usage
33
- prompt = "a function to calculate the factorial of a number"
34
- generated_code = generate_code(prompt)
35
- print(generated_code)
 
 
 
 
 
 
 
 
 
 
1
  from transformers import GPT2LMHeadModel, GPT2Tokenizer
2
+ import gradio as gr
3
 
4
  # Load the pre-trained GPT2 model and tokenizer
5
  model = GPT2LMHeadModel.from_pretrained("gpt2")
 
30
 
31
  return code
32
 
33
+ def predict(input_text):
34
+ output = generate_code(input_text)
35
+ return output
36
+
37
+ iface = gr.Interface(
38
+ fn=predict,
39
+ inputs=gr.Textbox(lines=2, placeholder="Enter your code generation prompt here..."),
40
+ outputs="text",
41
+ title="Code Generation with GPT2",
42
+ description="Generate Python code based on your input prompt."
43
+ )
44
+
45
+ iface.launch()