zainulabedin949 commited on
Commit
2d2a8d4
·
verified ·
1 Parent(s): 840aa20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -0
app.py CHANGED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pandas as pd
3
+ import numpy as np
4
+ import matplotlib.pyplot as plt
5
+ import gradio as gr
6
+ from groq import Groq
7
+
8
+ # Set the API key for Groq
9
+ os.environ["GROQ_API_KEY"] = "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"
10
+ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
11
+
12
+ def analyze_file(uploaded_file):
13
+ # Load the file into a pandas DataFrame
14
+ if uploaded_file.name.endswith('.csv'):
15
+ df = pd.read_csv(uploaded_file.name)
16
+ elif uploaded_file.name.endswith('.xlsx'):
17
+ df = pd.read_excel(uploaded_file.name)
18
+
19
+ # Perform basic data analysis
20
+ if 'Gain (dB)' in df.columns and 'Frequency (GHz)' in df.columns:
21
+ mean_gain = df['Gain (dB)'].mean()
22
+ median_gain = df['Gain (dB)'].median()
23
+ std_dev_gain = df['Gain (dB)'].std()
24
+
25
+ # Plot the data
26
+ fig, ax = plt.subplots()
27
+ ax.plot(df['Frequency (GHz)'], df['Gain (dB)'], label='Gain (dB)', color='blue')
28
+ ax.set_xlabel('Frequency (GHz)')
29
+ ax.set_ylabel('Gain (dB)')
30
+ ax.set_title('Gain vs Frequency')
31
+ ax.legend()
32
+ plt.close(fig) # Close to avoid inline display
33
+
34
+ # Send summary to Groq API for analysis
35
+ data_summary = f"""
36
+ The dataset contains simulation results for antennas. The frequency range is from 1 GHz to 10 GHz.
37
+ - The antenna's gain increases from 5 dB to 30 dB as frequency increases.
38
+ - Efficiency is consistently above 90%, with the highest reaching 99%.
39
+ """
40
+
41
+ chat_completion = client.chat.completions.create(
42
+ messages=[{
43
+ "role": "user",
44
+ "content": f"Analyze this data summary: {data_summary}",
45
+ }],
46
+ model="llama-3.3-70b-versatile", # Ensure this model is supported by Groq
47
+ )
48
+
49
+ groq_analysis = chat_completion.choices[0].message.content
50
+
51
+ return mean_gain, median_gain, std_dev_gain, fig, groq_analysis
52
+ else:
53
+ return "Required columns 'Gain (dB)' or 'Frequency (GHz)' not found in the dataset."
54
+
55
+ # Create the Gradio interface
56
+ iface = gr.Interface(
57
+ fn=analyze_file,
58
+ inputs=gr.inputs.File(label="Upload CSV or Excel File"),
59
+ outputs=[
60
+ gr.outputs.Textbox(label="Mean Gain"),
61
+ gr.outputs.Textbox(label="Median Gain"),
62
+ gr.outputs.Textbox(label="Standard Deviation of Gain"),
63
+ gr.outputs.Image(label="Plot"),
64
+ gr.outputs.Textbox(label="Groq's Analysis")
65
+ ],
66
+ title="Data Analysis and Visualization with Groq API",
67
+ description="Upload a CSV or Excel file to analyze the antenna data and get insights."
68
+ )
69
+
70
+ # Launch the interface
71
+ iface.launch()