Spaces:
Running
Running
Shahzad8515
commited on
Commit
•
72897f5
1
Parent(s):
72b8264
Update app.py
Browse files
app.py
CHANGED
@@ -2,65 +2,69 @@ import streamlit as st
|
|
2 |
import google.generativeai as genai
|
3 |
import os
|
4 |
|
5 |
-
#
|
6 |
-
os.
|
7 |
|
8 |
-
#
|
9 |
-
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
# Sidebar for input questions
|
12 |
-
st.sidebar.title("Prompt Engineering for AI Application")
|
13 |
|
14 |
-
# 1. Functionality of the AI application
|
15 |
-
functionality = st.sidebar.text_input(
|
16 |
-
|
17 |
-
|
18 |
-
)
|
19 |
|
20 |
-
# 2. Preferred programming language or framework
|
21 |
-
language = st.sidebar.text_input(
|
22 |
-
|
23 |
-
|
24 |
-
)
|
25 |
|
26 |
-
# 3. Specific libraries, tools, or models
|
27 |
-
libraries = st.sidebar.text_input(
|
28 |
-
|
29 |
-
|
30 |
-
)
|
31 |
|
32 |
-
# 4. Input data or format
|
33 |
-
input_data = st.sidebar.text_input(
|
34 |
-
|
35 |
-
|
36 |
-
)
|
37 |
|
38 |
-
# 5. Specific requirements or constraints
|
39 |
-
requirements = st.sidebar.text_input(
|
40 |
-
|
41 |
-
|
42 |
-
)
|
43 |
|
44 |
-
# Combine the user inputs into a prompt
|
45 |
-
prompt = f"""
|
46 |
-
Write a code to develop an AI application with the following details:
|
47 |
-
- Functionality: {functionality}
|
48 |
-
- Programming language or framework: {language}
|
49 |
-
- Specific libraries, tools, or models: {libraries}
|
50 |
-
- Input data or format: {input_data}
|
51 |
-
- Specific requirements or constraints: {requirements}
|
52 |
-
"""
|
53 |
|
54 |
-
# Main content
|
55 |
-
st.title("AI Code Generator using Google's Gemini Model")
|
56 |
-
st.write("Fill out the details in the sidebar to generate a proper prompt.")
|
57 |
|
58 |
-
if st.sidebar.button("Generate Code"):
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
|
64 |
-
# Footer
|
65 |
-
st.sidebar.write("---")
|
66 |
-
st.sidebar.write("This application helps you generate a prompt to write code for an AI application.")
|
|
|
2 |
import google.generativeai as genai
|
3 |
import os
|
4 |
|
5 |
+
# Retrieve the API key from environment variables
|
6 |
+
api_key = os.getenv("GOOGLE_API_KEY")
|
7 |
|
8 |
+
# Check if API key is provided
|
9 |
+
if not api_key:
|
10 |
+
st.error("API key is not set. Please set the GOOGLE_API_KEY environment variable.")
|
11 |
+
else:
|
12 |
+
# Configure Google Gemini API
|
13 |
+
genai.configure(api_key=api_key)
|
14 |
|
15 |
+
# Sidebar for input questions
|
16 |
+
st.sidebar.title("Prompt Engineering for AI Application")
|
17 |
|
18 |
+
# 1. Functionality of the AI application
|
19 |
+
functionality = st.sidebar.text_input(
|
20 |
+
"What specific functionality do you want the AI application to have?",
|
21 |
+
placeholder="e.g., image classification, text generation"
|
22 |
+
)
|
23 |
|
24 |
+
# 2. Preferred programming language or framework
|
25 |
+
language = st.sidebar.text_input(
|
26 |
+
"What programming language or framework do you prefer to use?",
|
27 |
+
placeholder="e.g., Python, TensorFlow"
|
28 |
+
)
|
29 |
|
30 |
+
# 3. Specific libraries, tools, or models
|
31 |
+
libraries = st.sidebar.text_input(
|
32 |
+
"Are there any specific libraries, tools, or models you want to integrate?",
|
33 |
+
placeholder="e.g., OpenAI's GPT, Whisper"
|
34 |
+
)
|
35 |
|
36 |
+
# 4. Input data or format
|
37 |
+
input_data = st.sidebar.text_input(
|
38 |
+
"What input data or format will the application work with?",
|
39 |
+
placeholder="e.g., text, images"
|
40 |
+
)
|
41 |
|
42 |
+
# 5. Specific requirements or constraints
|
43 |
+
requirements = st.sidebar.text_input(
|
44 |
+
"Do you have any specific requirements or constraints for the output?",
|
45 |
+
placeholder="e.g., performance, accuracy"
|
46 |
+
)
|
47 |
|
48 |
+
# Combine the user inputs into a prompt
|
49 |
+
prompt = f"""
|
50 |
+
Write a code to develop an AI application with the following details:
|
51 |
+
- Functionality: {functionality}
|
52 |
+
- Programming language or framework: {language}
|
53 |
+
- Specific libraries, tools, or models: {libraries}
|
54 |
+
- Input data or format: {input_data}
|
55 |
+
- Specific requirements or constraints: {requirements}
|
56 |
+
"""
|
57 |
|
58 |
+
# Main content
|
59 |
+
st.title("AI Code Generator using Google's Gemini Model")
|
60 |
+
st.write("Fill out the details in the sidebar to generate a proper prompt.")
|
61 |
|
62 |
+
if st.sidebar.button("Generate Code"):
|
63 |
+
model = genai.GenerativeModel('gemini-1.5-flash')
|
64 |
+
response = model.generate_content(prompt)
|
65 |
+
st.subheader("Generated Code:")
|
66 |
+
st.code(response.text, language='python')
|
67 |
|
68 |
+
# Footer
|
69 |
+
st.sidebar.write("---")
|
70 |
+
st.sidebar.write("This application helps you generate a prompt to write code for an AI application.")
|