zainulabedin949 commited on
Commit
bf4b27d
·
verified ·
1 Parent(s): dd912c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -7,7 +7,7 @@ import requests
7
 
8
  # Groq API Setup
9
  API_KEY = "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"
10
- API_URL = "https://api.groq.com/openai/v1/chat/completions"
11
 
12
  def analyze_file(uploaded_file):
13
  try:
@@ -19,11 +19,15 @@ def analyze_file(uploaded_file):
19
  else:
20
  return "Error: The uploaded file is neither CSV nor Excel."
21
 
 
 
 
22
  # Display the column names and first few rows for debugging
23
  print("Columns in the uploaded file:", df.columns)
24
  print("Preview of the uploaded data:", df.head())
25
- st.write(df.columns) # This will display column names in the UI for debugging
26
- st.write(df.head()) # This will display the first few rows in the UI
 
27
 
28
  # Check if required columns are present
29
  if 'Gain (dB)' in df.columns and 'Frequency (GHz)' in df.columns:
@@ -31,7 +35,7 @@ def analyze_file(uploaded_file):
31
  mean_gain = df['Gain (dB)'].mean()
32
  median_gain = df['Gain (dB)'].median()
33
  std_dev_gain = df['Gain (dB)'].std()
34
-
35
  # Display analysis results
36
  print(f"Mean Gain: {mean_gain}")
37
  print(f"Median Gain: {median_gain}")
@@ -52,7 +56,7 @@ def analyze_file(uploaded_file):
52
  - The antenna's gain increases from 5 dB to 30 dB as frequency increases.
53
  - Efficiency is consistently above 90%, with the highest reaching 99%.
54
  """
55
-
56
  headers = {
57
  "Authorization": f"Bearer {API_KEY}",
58
  "Content-Type": "application/json"
@@ -63,9 +67,8 @@ def analyze_file(uploaded_file):
63
  "model": "llama-3.3-70b-versatile" # Ensure this model is supported by Groq
64
  }
65
 
66
-
67
  # Send the request to Groq API
68
- response = requests.post(API_URL, json=payload, headers=headers, timeout=30) # 30 seconds timeout
69
  if response.status_code == 200:
70
  groq_analysis = response.json()["choices"][0]["message"]["content"]
71
  else:
@@ -97,4 +100,3 @@ iface = gr.Interface(
97
 
98
  # Launch the interface
99
  iface.launch()
100
-
 
7
 
8
  # Groq API Setup
9
  API_KEY = "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"
10
+ API_URL = "https://api.groq.com/openai/v1/chat/completions" # Updated API URL
11
 
12
  def analyze_file(uploaded_file):
13
  try:
 
19
  else:
20
  return "Error: The uploaded file is neither CSV nor Excel."
21
 
22
+ # Clean up the column names by stripping any leading/trailing spaces
23
+ df.columns = df.columns.str.strip()
24
+
25
  # Display the column names and first few rows for debugging
26
  print("Columns in the uploaded file:", df.columns)
27
  print("Preview of the uploaded data:", df.head())
28
+ # Display column names and preview in the Gradio UI for debugging
29
+ st.write(df.columns)
30
+ st.write(df.head())
31
 
32
  # Check if required columns are present
33
  if 'Gain (dB)' in df.columns and 'Frequency (GHz)' in df.columns:
 
35
  mean_gain = df['Gain (dB)'].mean()
36
  median_gain = df['Gain (dB)'].median()
37
  std_dev_gain = df['Gain (dB)'].std()
38
+
39
  # Display analysis results
40
  print(f"Mean Gain: {mean_gain}")
41
  print(f"Median Gain: {median_gain}")
 
56
  - The antenna's gain increases from 5 dB to 30 dB as frequency increases.
57
  - Efficiency is consistently above 90%, with the highest reaching 99%.
58
  """
59
+
60
  headers = {
61
  "Authorization": f"Bearer {API_KEY}",
62
  "Content-Type": "application/json"
 
67
  "model": "llama-3.3-70b-versatile" # Ensure this model is supported by Groq
68
  }
69
 
 
70
  # Send the request to Groq API
71
+ response = requests.post(API_URL, json=payload, headers=headers)
72
  if response.status_code == 200:
73
  groq_analysis = response.json()["choices"][0]["message"]["content"]
74
  else:
 
100
 
101
  # Launch the interface
102
  iface.launch()