File size: 2,149 Bytes
acff9e8
966b73b
acff9e8
966b73b
 
5e07bcf
966b73b
 
deba9cd
 
966b73b
acff9e8
5bb27d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
966b73b
 
 
1875453
5bb27d2
 
966b73b
 
acff9e8
966b73b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e07bcf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import gradio as gr
from transformers import pipeline

# Load a GPT-Neo model fine-tuned for code generation
generator = pipeline('text-generation', model='EleutherAI/gpt-neo-2.7B')

def generate_code(prompt):
    # Generate code from the model
    responses = generator(prompt, max_length=500, num_return_sequences=1, temperature=0.1)
    # responses = generator(prompt, max_length=50, num_return_sequences=1, temperature=0.5)
    return responses[0]['generated_text']


input_textbox = gr.Textbox(label="We shall get back to you!", lines=3)
outputs = gr.Markdown()
# ex = gr.Examples(examples_list, input_textbox, examples_per_page = 50)
# demo = gr.Interface( 
#         fn=greet, 
#         inputs = [input_textbox], 
#         examples = examples_list,
#         outputs = outputs,
#         title = title, 
#         description="Your Python Projects Coding Companion!",
#         allow_flagging="never",
#         examples_per_page = 50,
#         theme=gr.themes.Default(),
#         )




# Create a Gradio Interface
iface = gr.Interface(
    fn=generate_code,
#    inputs=[gr.inputs.Textbox(lines=10, label="Type your code description here")],
    inputs=input_textbox, #"text",
    outputs=outputs, #[gr.outputs.Textbox(label="Generated Code")],
    examples=[["Create a Python function to add two numbers"]],
)

# Run the interface
if __name__ == "__main__":
    iface.launch()

#import gradio as gr
#from transformers import pipeline

# Load a small GPT model fine-tuned for Python code generation
#generator = pipeline('text-generation', model='microsoft/CodeGPT-small-py')

#def generate_code(prompt):
#    # Generate code from the model
#    responses = generator(prompt, max_length=150, num_return_sequences=1, temperature=0.5)
#    return responses[0]['generated_text']

# Create a Gradio Interface
#iface = gr.Interface(
#    fn=generate_code,
#    inputs=[gr.inputs.Textbox(lines=10, label="Type your code description here")],
#    outputs=[gr.outputs.Textbox(label="Generated Code")],
#    examples=[["Define a Python function to calculate factorial."]],
#)

# Run the interface
#if __name__ == "__main__":
#    iface.launch()