Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,68 +1,49 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 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 |
-
st.
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
question = generate_question(difficulty)
|
| 51 |
-
st.session_state["question"] = question
|
| 52 |
-
|
| 53 |
-
if "question" in st.session_state:
|
| 54 |
-
st.subheader("Generated Question")
|
| 55 |
-
st.write(st.session_state["question"])
|
| 56 |
-
answer = st.text_area("Your Answer")
|
| 57 |
-
|
| 58 |
-
if st.button("Submit Answer"):
|
| 59 |
-
entry = {
|
| 60 |
-
"name": name,
|
| 61 |
-
"difficulty": difficulty,
|
| 62 |
-
"question": st.session_state["question"],
|
| 63 |
-
"answer": answer
|
| 64 |
-
}
|
| 65 |
-
data = load_data()
|
| 66 |
-
data.append(entry)
|
| 67 |
-
save_data(data)
|
| 68 |
-
st.success("Your answer has been saved!")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import google.generativeai as genai
|
| 3 |
+
|
| 4 |
+
st.set_page_config(page_title="Gemini Prompt Generator", layout="centered")
|
| 5 |
+
|
| 6 |
+
st.title("π Gemini Prompt Generator")
|
| 7 |
+
|
| 8 |
+
# User input section
|
| 9 |
+
api_key = st.text_input("π Enter your Gemini API Key", type="password")
|
| 10 |
+
|
| 11 |
+
if api_key:
|
| 12 |
+
genai.configure(api_key=api_key)
|
| 13 |
+
|
| 14 |
+
prompt = st.text_area("π¬ Enter your prompt", "What is the velocity of an unladen swallow?")
|
| 15 |
+
system_instructions = st.text_area("π§ System Instructions", "You have a tendency to speak in riddles.")
|
| 16 |
+
|
| 17 |
+
model = st.selectbox("π€ Choose Gemini model", [
|
| 18 |
+
"gemini-1.0-pro",
|
| 19 |
+
"gemini-1.5-pro",
|
| 20 |
+
"gemini-1.5-flash",
|
| 21 |
+
"gemini-2.0-flash"
|
| 22 |
+
])
|
| 23 |
+
|
| 24 |
+
temperature = st.slider("π‘οΈ Temperature", min_value=0.0, max_value=2.0, value=0.5, step=0.05)
|
| 25 |
+
stop_sequence = st.text_input("β Stop Sequence (optional)", "")
|
| 26 |
+
|
| 27 |
+
# Handle unsupported features
|
| 28 |
+
if model == "gemini-1.0-pro":
|
| 29 |
+
if system_instructions:
|
| 30 |
+
st.warning("System instructions ignored. gemini-1.0-pro does not support system instructions.")
|
| 31 |
+
system_instructions = None
|
| 32 |
+
if temperature > 1:
|
| 33 |
+
st.info("Temperature set to 1. gemini-1.0-pro does not support values > 1.")
|
| 34 |
+
temperature = 1
|
| 35 |
+
|
| 36 |
+
if stop_sequence.strip() == "":
|
| 37 |
+
stop_sequence = None
|
| 38 |
+
|
| 39 |
+
if st.button("π Generate"):
|
| 40 |
+
try:
|
| 41 |
+
gen_model = genai.GenerativeModel(model, system_instruction=system_instructions)
|
| 42 |
+
config = genai.GenerationConfig(temperature=temperature, stop_sequences=[stop_sequence] if stop_sequence else [])
|
| 43 |
+
response = gen_model.generate_content(contents=[prompt], generation_config=config)
|
| 44 |
+
st.markdown("### β¨ Response")
|
| 45 |
+
st.write(response.text)
|
| 46 |
+
except Exception as e:
|
| 47 |
+
st.error(f"Error: {e}")
|
| 48 |
+
else:
|
| 49 |
+
st.info("Please enter your API key to continue.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|