Requirement.text
Browse filesgradio
requests
app.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
api_key = os.getenv("GROQ_API_KEY")
|
| 6 |
+
|
| 7 |
+
def analyze_mppt(voltage, current, power, temperature):
|
| 8 |
+
if not api_key:
|
| 9 |
+
return "Error: GROQ_API_KEY is missing."
|
| 10 |
+
|
| 11 |
+
prompt = (
|
| 12 |
+
f"You are an expert in solar energy and MPPT control.\n"
|
| 13 |
+
f"Given the following readings from a solar panel:\n"
|
| 14 |
+
f"- Voltage: {voltage} V\n"
|
| 15 |
+
f"- Current: {current} A\n"
|
| 16 |
+
f"- Power: {power} W\n"
|
| 17 |
+
f"- Temperature: {temperature} °C\n\n"
|
| 18 |
+
f"Provide an analysis of the system’s efficiency, whether MPPT is optimized, and any suggestions for improvement or maintenance."
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
headers = {
|
| 22 |
+
"Authorization": f"Bearer {api_key}",
|
| 23 |
+
"Content-Type": "application/json"
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
payload = {
|
| 27 |
+
"model": "llama3-8b-8192",
|
| 28 |
+
"messages": [
|
| 29 |
+
{"role": "system", "content": "You are a solar energy engineer specialized in MPPT systems."},
|
| 30 |
+
{"role": "user", "content": prompt}
|
| 31 |
+
],
|
| 32 |
+
"temperature": 0.2
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
try:
|
| 36 |
+
response = requests.post(
|
| 37 |
+
"https://api.groq.com/openai/v1/chat/completions",
|
| 38 |
+
headers=headers,
|
| 39 |
+
json=payload
|
| 40 |
+
)
|
| 41 |
+
return response.json()["choices"][0]["message"]["content"].strip()
|
| 42 |
+
except Exception as e:
|
| 43 |
+
return f"Error: {str(e)}"
|
| 44 |
+
|
| 45 |
+
iface = gr.Interface(
|
| 46 |
+
fn=analyze_mppt,
|
| 47 |
+
inputs=[
|
| 48 |
+
gr.Number(label="Voltage (V)"),
|
| 49 |
+
gr.Number(label="Current (A)"),
|
| 50 |
+
gr.Number(label="Power (W)"),
|
| 51 |
+
gr.Number(label="Temperature (°C)")
|
| 52 |
+
],
|
| 53 |
+
outputs=gr.Textbox(label="MPPT Analysis"),
|
| 54 |
+
title="IoT-based Solar Monitoring (MPPT Analysis)",
|
| 55 |
+
description="Enter solar panel readings to analyze MPPT performance using Groq's LLaMA 3 model."
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
if __name__ == "__main__":
|
| 59 |
+
iface.launch()
|