Spaces:
Sleeping
Sleeping
edit code again
Browse files
app.py
CHANGED
|
@@ -24,7 +24,6 @@ def generate_text(prompt, model, max_tokens, temperature):
|
|
| 24 |
"temperature": temperature,
|
| 25 |
},
|
| 26 |
)
|
| 27 |
-
# β
Extract and return generated text
|
| 28 |
if response and response.candidates:
|
| 29 |
return response.candidates[0].content.parts[0].text
|
| 30 |
else:
|
|
@@ -36,35 +35,30 @@ def generate_text(prompt, model, max_tokens, temperature):
|
|
| 36 |
# β
Streamlit Page Configuration
|
| 37 |
st.set_page_config(page_title="Gemini AI Text Generator", layout="centered")
|
| 38 |
|
| 39 |
-
# β
|
| 40 |
-
st.title("
|
| 41 |
-
st.
|
| 42 |
|
| 43 |
-
# β
|
| 44 |
-
st.
|
| 45 |
-
user_input = st.text_area("Write something...", height=150, placeholder="Example: Write a formal article about climate change.")
|
| 46 |
|
| 47 |
-
# β
|
| 48 |
-
|
|
|
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
max_tokens = st.slider("π Max Tokens (Word Length)", min_value=50, max_value=1000, value=300, step=50)
|
| 53 |
|
| 54 |
-
|
| 55 |
-
temperature = st.slider("π¨ Creativity Level (1-10)", min_value=1, max_value=10, value=5) / 10 # Scaling to 0.1 - 1.0
|
| 56 |
-
|
| 57 |
-
# β
Generate Button
|
| 58 |
-
st.markdown("### ")
|
| 59 |
if st.button("π Generate Text"):
|
| 60 |
if user_input.strip():
|
| 61 |
with st.spinner("β¨ Generating response..."):
|
| 62 |
result = generate_text(user_input, model, max_tokens, temperature)
|
| 63 |
-
st.
|
| 64 |
st.write(result)
|
| 65 |
else:
|
| 66 |
st.warning("β οΈ Please enter a prompt before generating text.")
|
| 67 |
|
| 68 |
# β
Footer
|
| 69 |
st.markdown("---")
|
| 70 |
-
st.
|
|
|
|
| 24 |
"temperature": temperature,
|
| 25 |
},
|
| 26 |
)
|
|
|
|
| 27 |
if response and response.candidates:
|
| 28 |
return response.candidates[0].content.parts[0].text
|
| 29 |
else:
|
|
|
|
| 35 |
# β
Streamlit Page Configuration
|
| 36 |
st.set_page_config(page_title="Gemini AI Text Generator", layout="centered")
|
| 37 |
|
| 38 |
+
# β
Title & Description
|
| 39 |
+
st.title("π€ Gemini AI Text Generator")
|
| 40 |
+
st.write("Generate AI-powered text by entering a prompt and customizing the settings.")
|
| 41 |
|
| 42 |
+
# β
Input Prompt
|
| 43 |
+
user_input = st.text_area("π Enter Your Prompt:", height=150, placeholder="Example: Write a formal article about climate change.")
|
|
|
|
| 44 |
|
| 45 |
+
# β
Sliders (Aligned Below Prompt)
|
| 46 |
+
temperature = st.slider("π¨ Creativity Level (1-10)", min_value=1, max_value=10, value=5) / 10
|
| 47 |
+
max_tokens = st.slider("π Max Tokens (Word Length)", min_value=50, max_value=1000, value=300, step=50)
|
| 48 |
|
| 49 |
+
# β
AI Model Selection (Below Sliders)
|
| 50 |
+
model = st.selectbox("π€ Choose AI Model", ["gemini-pro", "gemini-pro-code"])
|
|
|
|
| 51 |
|
| 52 |
+
# β
Generate Button (Below Model Selection)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
if st.button("π Generate Text"):
|
| 54 |
if user_input.strip():
|
| 55 |
with st.spinner("β¨ Generating response..."):
|
| 56 |
result = generate_text(user_input, model, max_tokens, temperature)
|
| 57 |
+
st.subheader("π― Generated Response")
|
| 58 |
st.write(result)
|
| 59 |
else:
|
| 60 |
st.warning("β οΈ Please enter a prompt before generating text.")
|
| 61 |
|
| 62 |
# β
Footer
|
| 63 |
st.markdown("---")
|
| 64 |
+
st.write("πΉ *Powered by Gemini AI* | πΉ *Developed with Streamlit*")
|