Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 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,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 =
|
| 33 |
-
median_gain =
|
| 34 |
-
std_dev_gain =
|
| 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(
|
| 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')
|