zainulabedin949 commited on
Commit
9722cdb
·
verified ·
1 Parent(s): a7a24e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -11,11 +11,11 @@ API_URL = "https://api.groq.com/openai/v1/chat/completions" # Updated API URL
11
 
12
  def analyze_file(uploaded_file):
13
  try:
14
- # Load the file into a pandas DataFrame from the uploaded file (in memory)
15
  if uploaded_file.name.endswith('.csv'):
16
- df = pd.read_csv(uploaded_file) # Read directly from memory
17
  elif uploaded_file.name.endswith('.xlsx'):
18
- df = pd.read_excel(uploaded_file) # Read directly from memory
19
  else:
20
  return "Error: The uploaded file is neither CSV nor Excel."
21
 
@@ -28,10 +28,14 @@ def analyze_file(uploaded_file):
28
 
29
  # Check if required columns are present
30
  if 'Gain (dB)' in df.columns and 'Frequency (GHz)' in df.columns:
 
 
 
 
31
  # Perform basic data analysis
32
- mean_gain = df['Gain (dB)'].mean()
33
- median_gain = df['Gain (dB)'].median()
34
- std_dev_gain = df['Gain (dB)'].std()
35
 
36
  # Display analysis results
37
  st.write(f"Mean Gain: {mean_gain}")
@@ -40,7 +44,7 @@ def analyze_file(uploaded_file):
40
 
41
  # Plotting the data
42
  fig, ax = plt.subplots()
43
- ax.plot(df['Frequency (GHz)'], df['Gain (dB)'], label='Gain (dB)', color='blue')
44
  ax.set_xlabel('Frequency (GHz)')
45
  ax.set_ylabel('Gain (dB)')
46
  ax.set_title('Gain vs Frequency')
 
11
 
12
  def analyze_file(uploaded_file):
13
  try:
14
+ # Load the file into a pandas DataFrame
15
  if uploaded_file.name.endswith('.csv'):
16
+ df = pd.read_csv(uploaded_file)
17
  elif uploaded_file.name.endswith('.xlsx'):
18
+ df = pd.read_excel(uploaded_file)
19
  else:
20
  return "Error: The uploaded file is neither CSV nor Excel."
21
 
 
28
 
29
  # Check if required columns are present
30
  if 'Gain (dB)' in df.columns and 'Frequency (GHz)' in df.columns:
31
+ # Convert pandas columns to numpy arrays before performing operations
32
+ gain_values = np.array(df['Gain (dB)'])
33
+ freq_values = np.array(df['Frequency (GHz)'])
34
+
35
  # Perform basic data analysis
36
+ mean_gain = np.mean(gain_values)
37
+ median_gain = np.median(gain_values)
38
+ std_dev_gain = np.std(gain_values)
39
 
40
  # Display analysis results
41
  st.write(f"Mean Gain: {mean_gain}")
 
44
 
45
  # Plotting the data
46
  fig, ax = plt.subplots()
47
+ ax.plot(freq_values, gain_values, label='Gain (dB)', color='blue')
48
  ax.set_xlabel('Frequency (GHz)')
49
  ax.set_ylabel('Gain (dB)')
50
  ax.set_title('Gain vs Frequency')