harizh commited on
Commit
80b448d
·
verified ·
1 Parent(s): 7f1de55

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import google.generativeai as genai
3
+ import os
4
+ from dotenv import load_dotenv
5
+
6
+ # Authentication
7
+ load_dotenv()
8
+ GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
9
+ genai.configure(api_key=GOOGLE_API_KEY)
10
+ model = genai.GenerativeModel('gemini-1.5-flash')
11
+
12
+ def generate_code(logic, time_complexity, space_complexity, language, others):
13
+ prompt = f"""
14
+ Generate Code by considering the following parameter and conditions. The code should not have any comments.
15
+ 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.
16
+ Logic: {logic}
17
+ Time Complexity: {time_complexity}
18
+ Space Complexity: {space_complexity}
19
+ Language: {language}
20
+ or{others}
21
+ """
22
+ response = model.generate_content(prompt)
23
+ return response.text
24
+
25
+ complexity_options = ["O(1)", "O(log N)", "O(N)", "O(N log N)", "O(N²)", "O(N³)", "O(2^N)", "O(N!)"]
26
+ language_options = ["Python", "Java", "JavaScript", "C", "C++", "Others"]
27
+
28
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
29
+
30
+ gr.Markdown("# Humanly Code Generator")
31
+ gr.Markdown("## \n\n<style>h1, h2, h3, h4, h5, h6 { font-size: 40px !important; text-align:center !important; display: block !important;}</style>",label="")
32
+ gr.Image("CodeBanner.gif",label="☀︎")
33
+ with gr.Row():
34
+ logic = gr.Textbox(label="Provide the logic for the code.")
35
+
36
+ with gr.Row():
37
+ time_complexity = gr.Radio(complexity_options, label="Time Complexity",
38
+ info="Choose the Time Complexity for your code.")
39
+ space_complexity = gr.Radio(complexity_options, label="Space Complexity",
40
+ info="Choose the Space Complexity for your code.")
41
+
42
+ with gr.Row():
43
+ language = gr.Radio(language_options, label="Programming Language",
44
+ info="Choose the programming language. If some other language then type in the next textbox.")
45
+ others = gr.Textbox(label="Specify Language")
46
+
47
+ output = gr.Markdown(label="Generated Code", )
48
+
49
+ generate_button = gr.Button("Generate Code")
50
+ generate_button.click(fn=generate_code,
51
+ inputs=[logic, time_complexity, space_complexity, language, others],
52
+ outputs=output)
53
+
54
+ demo.launch()