File size: 1,925 Bytes
ef3d164
d16f623
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import google.generativeai as genai

st.set_page_config(page_title="Gemini Prompt Generator", layout="centered")

st.title("🌟 Gemini Prompt Generator")

# User input section
api_key = st.text_input("πŸ”‘ Enter your Gemini API Key", type="password")

if api_key:
    genai.configure(api_key=api_key)

    prompt = st.text_area("πŸ’¬ Enter your prompt", "What is the velocity of an unladen swallow?")
    system_instructions = st.text_area("🧠 System Instructions", "You have a tendency to speak in riddles.")
    
    model = st.selectbox("πŸ€– Choose Gemini model", [
        "gemini-1.0-pro",
        "gemini-1.5-pro",
        "gemini-1.5-flash",
        "gemini-2.0-flash"
    ])
    
    temperature = st.slider("🌑️ Temperature", min_value=0.0, max_value=2.0, value=0.5, step=0.05)
    stop_sequence = st.text_input("β›” Stop Sequence (optional)", "")
    
    # Handle unsupported features
    if model == "gemini-1.0-pro":
        if system_instructions:
            st.warning("System instructions ignored. gemini-1.0-pro does not support system instructions.")
            system_instructions = None
        if temperature > 1:
            st.info("Temperature set to 1. gemini-1.0-pro does not support values > 1.")
            temperature = 1

    if stop_sequence.strip() == "":
        stop_sequence = None
    
    if st.button("πŸš€ Generate"):
        try:
            gen_model = genai.GenerativeModel(model, system_instruction=system_instructions)
            config = genai.GenerationConfig(temperature=temperature, stop_sequences=[stop_sequence] if stop_sequence else [])
            response = gen_model.generate_content(contents=[prompt], generation_config=config)
            st.markdown("### ✨ Response")
            st.write(response.text)
        except Exception as e:
            st.error(f"Error: {e}")
else:
    st.info("Please enter your API key to continue.")