MLDeveloper commited on
Commit
27cc353
·
verified ·
1 Parent(s): 8023daf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -17
app.py CHANGED
@@ -4,11 +4,18 @@ import numpy as np
4
  import matplotlib.pyplot as plt
5
  import openai
6
 
 
 
 
 
7
  # Load the solar data CSV file
8
  df = pd.read_csv('https://huggingface.co/spaces/MLDeveloper/AI_based_Solar_Project_Estimation_Tool/resolve/main/solar_data_india_2024.csv')
9
 
10
- # Set up the openai API key (replace with your actual OpenAI API key)
11
- openai.api_key = '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'
 
 
 
12
 
13
  # Streamlit UI
14
  st.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")
@@ -36,7 +43,7 @@ if submitted and location and roof_size > 0 and electricity_bill >= 0:
36
  ghi = state_data['Avg_GHI (kWh/m²/day)']
37
  solar_cost_per_kw = state_data['Solar_Cost_per_kW (₹)']
38
 
39
- # Use LLM to generate solar project estimate (cost, savings, payback period)
40
  prompt = f"""
41
  Estimate the solar system for the location '{location}' based on the following details:
42
  Roof size: {roof_size} sq meters
@@ -52,22 +59,31 @@ if submitted and location and roof_size > 0 and electricity_bill >= 0:
52
  5. Payback period in years
53
  """
54
 
55
- # Get response from OpenAI API
56
- response = openai.Completion.create(
57
- engine="gpt-4", # You can change this to another GPT model if needed
58
- prompt=prompt,
59
- max_tokens=250,
60
- n=1,
61
- stop=None,
62
- temperature=0.7,
 
 
 
 
 
 
 
63
  )
64
 
65
- # Extract the result
66
- result = response.choices[0].text.strip()
67
-
68
- # Display the response from the model
69
- st.subheader("Estimated Solar System Details:")
70
- st.write(result)
 
 
71
 
72
  else:
73
  st.error("Sorry, the location entered does not match any available data.")
 
4
  import matplotlib.pyplot as plt
5
  import openai
6
 
7
+ import streamlit as st
8
+ import pandas as pd
9
+ import requests
10
+
11
  # Load the solar data CSV file
12
  df = pd.read_csv('https://huggingface.co/spaces/MLDeveloper/AI_based_Solar_Project_Estimation_Tool/resolve/main/solar_data_india_2024.csv')
13
 
14
+ # Set up the Gemini API key (replace with your actual Gemini API key)
15
+ GEMINI_API_KEY = 'AIzaSyAGGP8I7c0YmA8xKZsEdAF9AF3ElaPoEn4'
16
+
17
+ # Set the API endpoint for Gemini
18
+ GEMINI_API_URL = "https://gemini.googleapis.com/v1/completions" # Example URL, please check the actual URL
19
 
20
  # Streamlit UI
21
  st.set_page_config(page_title="AI-based Solar Project Estimation Tool", layout="centered")
 
43
  ghi = state_data['Avg_GHI (kWh/m²/day)']
44
  solar_cost_per_kw = state_data['Solar_Cost_per_kW (₹)']
45
 
46
+ # Use Gemini API to generate solar project estimate (cost, savings, payback period)
47
  prompt = f"""
48
  Estimate the solar system for the location '{location}' based on the following details:
49
  Roof size: {roof_size} sq meters
 
59
  5. Payback period in years
60
  """
61
 
62
+ # Request to Gemini API (Adjust headers and body according to Gemini API documentation)
63
+ response = requests.post(
64
+ GEMINI_API_URL,
65
+ headers={
66
+ "Authorization": f"Bearer {GEMINI_API_KEY}",
67
+ "Content-Type": "application/json"
68
+ },
69
+ json={
70
+ "model": "gemini-model-xyz", # Use the actual Gemini model name
71
+ "prompt": prompt,
72
+ "max_tokens": 250,
73
+ "temperature": 0.7,
74
+ "top_p": 1.0,
75
+ "n": 1
76
+ }
77
  )
78
 
79
+ # Check for successful response
80
+ if response.status_code == 200:
81
+ result = response.json().get("choices", [])[0].get("text", "").strip()
82
+ # Display the response from the Gemini model
83
+ st.subheader("Estimated Solar System Details:")
84
+ st.write(result)
85
+ else:
86
+ st.error(f"Error: {response.status_code}. Unable to get response from Gemini API.")
87
 
88
  else:
89
  st.error("Sorry, the location entered does not match any available data.")