Spaces:
Running
Running
import streamlit as st | |
import google.generativeai as genai | |
import os | |
# Retrieve the API key from environment variables | |
api_key = os.getenv("google_api_key") | |
# Check if API key is provided | |
if not api_key: | |
st.error("API key is not set. Please set the GOOGLE_API_KEY environment variable.") | |
else: | |
# Configure Google Gemini API | |
genai.configure(api_key=api_key) | |
# Sidebar for input questions | |
st.sidebar.title("Prompt Engineering for AI Application") | |
# 1. Functionality of the AI application | |
functionality = st.sidebar.text_input( | |
"What specific functionality do you want the AI application to have?", | |
placeholder="e.g., image classification, text generation" | |
) | |
# 2. Preferred programming language or framework | |
language = st.sidebar.text_input( | |
"What programming language or framework do you prefer to use?", | |
placeholder="e.g., Python, TensorFlow" | |
) | |
# 3. Specific libraries, tools, or models | |
libraries = st.sidebar.text_input( | |
"Are there any specific libraries, tools, or models you want to integrate?", | |
placeholder="e.g., OpenAI's GPT, Whisper" | |
) | |
# 4. Input data or format | |
input_data = st.sidebar.text_input( | |
"What input data or format will the application work with?", | |
placeholder="e.g., text, images" | |
) | |
# 5. Specific requirements or constraints | |
requirements = st.sidebar.text_input( | |
"Do you have any specific requirements or constraints for the output?", | |
placeholder="e.g., performance, accuracy" | |
) | |
# Combine the user inputs into a prompt | |
prompt = f""" | |
Write a code to develop an AI application with the following details: | |
- Functionality: {functionality} | |
- Programming language or framework: {language} | |
- Specific libraries, tools, or models: {libraries} | |
- Input data or format: {input_data} | |
- Specific requirements or constraints: {requirements} | |
""" | |
# Main content | |
st.title("AI Code Generator using Google's Gemini Model") | |
st.write("Fill out the details in the sidebar to generate a proper prompt.") | |
if st.sidebar.button("Generate Code"): | |
model = genai.GenerativeModel('gemini-1.5-flash') | |
response = model.generate_content(prompt) | |
st.subheader("Generated Code:") | |
st.code(response.text, language='python') | |
# Footer | |
st.sidebar.write("---") | |
st.sidebar.write("This application helps you generate a prompt to write code for an AI application.") | |