lily0n commited on
Commit
fcd9551
Β·
verified Β·
1 Parent(s): c012bc0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -39
app.py CHANGED
@@ -1,41 +1,49 @@
1
  import streamlit as st
2
- import pandas as pd
3
- import matplotlib.pyplot as plt
4
- import seaborn as sns
5
- import numpy as np
6
-
7
-
8
-
9
-
10
- # App Title
11
- st.title("πŸ“Š Streamlit Data Analysis Tool")
12
-
13
- # Upload CSV File
14
- uploaded_file = st.file_uploader("Upload a CSV file", type=["csv"])
15
-
16
- if uploaded_file:
17
- df = pd.read_csv(uploaded_file)
18
- st.write("### Preview of Uploaded Data")
19
- st.dataframe(df.head())
20
-
21
- # Dropdown for column selection
22
- numeric_cols = df.select_dtypes(include=['number']).columns.tolist()
23
- if numeric_cols:
24
- col_to_analyze = st.selectbox("Select a column to analyze", numeric_cols)
25
-
26
- # Summary statistics
27
- st.write("### Summary Statistics")
28
- st.write(df[col_to_analyze].describe())
29
-
30
- # Histogram Slider
31
- bins = st.slider("Number of bins for histogram", min_value=5, max_value=50, value=20)
32
-
33
- # Plot Histogram
34
- fig, ax = plt.subplots()
35
- sns.histplot(df[col_to_analyze], bins=bins, kde=True, ax=ax)
36
- st.pyplot(fig)
 
 
37
  else:
38
- st.warning("No numeric columns found in the dataset.")
39
-
40
- else:
41
- st.info("Please upload a CSV file to get started.")
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import google.generativeai as genai
3
+
4
+ # Set up Gemini API
5
+ genai.configure(api_key="AIzaSyBQqw4RV3XdTFuPud7mkoHNPfxQm5EnOrc") # Replace with your Gemini API key
6
+
7
+ # Set up the model
8
+ generation_config = {
9
+ "temperature": 0.9, # Controls creativity (0 = strict, 1 = creative)
10
+ "top_p": 1,
11
+ "top_k": 1,
12
+ "max_output_tokens": 2048, # Maximum length of the response
13
+ }
14
+
15
+ safety_settings = [
16
+ {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
17
+ {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
18
+ {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
19
+ {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
20
+ ]
21
+
22
+ model = genai.GenerativeModel(
23
+ model_name="gemini-pro",
24
+ generation_config=generation_config,
25
+ safety_settings=safety_settings,
26
+ )
27
+
28
+ # Streamlit App
29
+ st.title("πŸ“– Gemini Story Generator")
30
+ st.write("Enter a prompt, and Gemini AI will generate a story for you!")
31
+
32
+ # User input
33
+ user_prompt = st.text_area("Enter your story prompt:", "Once upon a time...")
34
+
35
+ # Generate story button
36
+ if st.button("Generate Story"):
37
+ if user_prompt.strip() == "":
38
+ st.warning("Please enter a prompt!")
39
  else:
40
+ try:
41
+ # Generate response using Gemini AI
42
+ response = model.generate_content(
43
+ f"Write a creative and engaging story suitable for elementary school children based on this prompt: {user_prompt}"
44
+ )
45
+ st.write("### Here's Your Story:")
46
+ st.write(response.text)
47
+ st.success("🌟 The End 🌟")
48
+ except Exception as e:
49
+ st.error(f"An error occurred: {e}. Please try again.")