mherlie commited on
Commit
1b74fd0
Β·
1 Parent(s): 96c7057
Files changed (2) hide show
  1. .streamlit/secrets.toml +1 -0
  2. app.py +67 -0
.streamlit/secrets.toml ADDED
@@ -0,0 +1 @@
 
 
1
+ GEMINI_API_KEY = "AIzaSyC4ra1iTJVMmEI9dF4Di8W-2gV8lXmvu54"
app.py CHANGED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ import google.generativeai as genai # βœ… Gemini API library
4
+
5
+ # Load API key securely
6
+ api_key = os.getenv("GEMINI_API_KEY", st.secrets.get("GEMINI_API_KEY"))
7
+
8
+ # Check if API key is available
9
+ if not api_key:
10
+ st.error("⚠️ API key is missing! Set GEMINI_API_KEY as an environment variable or in Streamlit Secrets.")
11
+ st.stop()
12
+
13
+ # Configure Gemini API
14
+ genai.configure(api_key=api_key)
15
+
16
+ # Function to generate AI response
17
+ def call_gemini_api(prompt, model, max_tokens, temperature):
18
+ try:
19
+ model = genai.GenerativeModel(model)
20
+ response = model.generate_content(
21
+ prompt,
22
+ generation_config={
23
+ "max_output_tokens": max_tokens,
24
+ "temperature": temperature,
25
+ },
26
+ )
27
+
28
+ # βœ… Extract only the generated text
29
+ if response and response.candidates:
30
+ return response.candidates[0].content.parts[0].text
31
+ else:
32
+ return "⚠️ No valid response from Gemini AI."
33
+
34
+ except Exception as e:
35
+ return f"Error: {str(e)}"
36
+
37
+ # Configure Streamlit page
38
+ st.set_page_config(page_title="Gemini AI Text Generator", layout="centered")
39
+
40
+ # UI Elements
41
+ st.title("πŸ“ Creative AI Assistant")
42
+ st.write("Generate text with AI by providing a prompt below!")
43
+
44
+ # User input fields
45
+ user_input = st.text_area("✍️ Enter your prompt here:", height=150)
46
+
47
+ col1, col2 = st.columns(2)
48
+
49
+ with col1:
50
+ model = st.selectbox("πŸ€– Choose AI Model:", ["gemini-pro", "gemini-pro-code"])
51
+ max_tokens = st.slider("πŸ“ Max Tokens (Word Length)", min_value=50, max_value=1000, value=200, step=50)
52
+
53
+ with col2:
54
+ temperature = st.slider("🎨 Creativity Level (0 = Predictable, 1 = Creative)", min_value=0.0, max_value=1.0, value=0.7, step=0.1)
55
+
56
+ # Generate button
57
+ if st.button("πŸš€ Generate Text"):
58
+ if user_input.strip():
59
+ st.subheader("πŸ“Œ Generated Response:")
60
+ result = call_gemini_api(user_input, model, max_tokens, temperature)
61
+ st.write(result)
62
+ else:
63
+ st.warning("⚠️ Please enter a prompt before generating text.")
64
+
65
+ # Footer
66
+ st.markdown("---")
67
+ st.caption("πŸ”Ή *Powered by Gemini AI* | πŸ”Ή *Developed with Streamlit*")