File size: 2,379 Bytes
80b448d
 
 
 
 
 
 
 
 
 
 
 
 
 
1d00b91
 
80b448d
 
 
 
 
 
 
 
 
 
 
 
1d00b91
80b448d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import google.generativeai as genai
import os
from dotenv import load_dotenv

# Authentication
load_dotenv()
GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
genai.configure(api_key=GOOGLE_API_KEY)
model = genai.GenerativeModel('gemini-1.5-flash')

def generate_code(logic, time_complexity, space_complexity, language, others):
    prompt = f"""
    Generate Code by considering the following parameter and conditions. The code should not have any comments. 
    The code should look like Human typed code. 
    The naming of the variables and other functions should be small and looks like human created code. 
    Logic: {logic}
    Time Complexity: {time_complexity}
    Space Complexity: {space_complexity}
    Language: {language}
    or{others}
    """
    response = model.generate_content(prompt)
    return response.text

complexity_options = ["O(1)", "O(log N)", "O(N)", "O(N log N)", "O(N²)", "O(N³)", "O(2^N)", "O(N!)"]
language_options = ["Python", "Java", "JavaScript", "C", "C++", "Others"]

with gr.Blocks(theme=gr.themes.Soft(primary_hue="sky", secondary_hue="blue")) as demo:
    
    gr.Markdown("# Humanly Code Generator")
    gr.Markdown("## \n\n<style>h1, h2, h3, h4, h5, h6 { font-size: 40px !important; text-align:center !important; display: block !important;}</style>",label="")
    gr.Image("CodeBanner.gif",label="☀︎")
    with gr.Row():
        logic = gr.Textbox(label="Provide the logic for the code.")

    with gr.Row():
        time_complexity = gr.Radio(complexity_options, label="Time Complexity",
                                   info="Choose the Time Complexity for your code.")
        space_complexity = gr.Radio(complexity_options, label="Space Complexity",
                                    info="Choose the Space Complexity for your code.")

    with gr.Row():
        language = gr.Radio(language_options, label="Programming Language",
                            info="Choose the programming language. If some other language then type in the next textbox.")
        others = gr.Textbox(label="Specify Language")

    output = gr.Markdown(label="Generated Code", )

    generate_button = gr.Button("Generate Code")
    generate_button.click(fn=generate_code,
                          inputs=[logic, time_complexity, space_complexity, language, others],
                          outputs=output)

demo.launch()