Wall06 commited on
Commit
223f148
·
verified ·
1 Parent(s): c897235

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -76
app.py CHANGED
@@ -2,16 +2,13 @@ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
4
 
5
- # --- 1. SETUP API CONNECTION ---
6
  API_KEY = os.getenv("HF_API_KEY")
7
-
8
  if not API_KEY:
9
  raise ValueError("⚠️ HF_API_KEY not found. Set it in your environment variables.")
10
 
11
- # Use a free, supported model
12
- client = InferenceClient("tiiuae/falcon-7b-instruct", token=API_KEY)
13
 
14
- # --- 2. DEFINE THE LOGIC ---
15
  def analyze_biodiversity(species, habitat, region, activity, noise, flow, pollutants, breeding, disturbance):
16
  prompt = f"""
17
  You are BioVigilus, an expert AI Ecologist. Create a short, professional Impact Report with emojis.
@@ -33,82 +30,25 @@ OUTPUT REQUIRED:
33
  """
34
 
35
  try:
36
- # Falcon returns a list of generations
37
- response = client.text_generation(prompt, max_new_tokens=500, temperature=0.5)
38
  return response[0].generated_text.strip()
39
  except Exception as e:
40
  return f"⚠️ Analysis Failed: {str(e)}"
41
 
42
- # --- 3. CUSTOM STYLE ---
43
- custom_style = """
44
- <style>
45
- body, .gradio-container { background-color: #0f172a !important; color: #e2e8f0 !important; }
46
- h1 { color: #34d399 !important; text-align: center; font-size: 2.5em !important; margin-bottom: 0; }
47
- h3 { color: #94a3b8 !important; text-align: center; margin-top: 0; }
48
-
49
- button.primary {
50
- background: linear-gradient(90deg, #10b981, #06b6d4) !important;
51
- border: none !important;
52
- color: black !important;
53
- font-weight: bold !important;
54
- font-size: 1.2em !important;
55
- }
56
- button.primary:hover { transform: scale(1.02); }
57
-
58
- .gr-box, .gr-input, input, textarea {
59
- background-color: #1e293b !important;
60
- border: 1px solid #334155 !important;
61
- color: white !important;
62
- }
63
- label span { color: #64748b !important; font-weight: bold; }
64
-
65
- .output-text { font-family: monospace; background-color: #1e293b; padding: 15px; border-radius: 8px; border: 1px solid #475569; }
66
- </style>
67
- """
68
-
69
- # --- 4. BUILD THE APP ---
70
  with gr.Blocks() as app:
71
-
72
- gr.HTML(custom_style)
73
-
74
- with gr.Row():
75
- gr.Markdown("# 🌿 BioVigilus")
76
- gr.Markdown("### *AI-Powered Biodiversity Impact Analyzer*")
77
-
78
- with gr.Row():
79
- with gr.Column():
80
- gr.Markdown("### 🦅 Species Info")
81
- species = gr.Textbox(label="Species Name", placeholder="e.g. Snow Leopard")
82
- habitat = gr.Textbox(label="Habitat", placeholder="e.g. Alpine Cliffs")
83
- region = gr.Textbox(label="Region", placeholder="e.g. Gilgit-Baltistan")
84
- activity = gr.Textbox(label="Activity", placeholder="e.g. Road Construction")
85
- breeding = gr.Radio(["Yes", "No"], label="Breeding Season?", value="No")
86
-
87
- with gr.Column():
88
- gr.Markdown("### 📉 Stress Factors")
89
- noise = gr.Slider(0, 100, label="Noise Level")
90
- flow = gr.Slider(0, 100, label="Water Flow Change")
91
- disturbance = gr.Slider(0, 100, label="Land Disturbance")
92
- pollutants = gr.Textbox(label="Pollutants", placeholder="Dust, Oil, Chemicals")
93
-
94
- btn = gr.Button("🔍 Analyze Ecological Impact", variant="primary")
95
-
96
- gr.Markdown("### 📋 Scientific Report")
97
- output = gr.Markdown("Results will appear here...", elem_classes=["output-text"])
98
-
99
- gr.Examples(
100
- examples=[
101
- ["Snow Leopard", "Rocky Mountains", "Gilgit", "Highway Construction", 85, 10, "Explosive Dust", "Yes", 70],
102
- ["Indus Dolphin", "River Indus", "Sukkur", "Bridge Maintenance", 60, 80, "Oil Leak", "No", 20]
103
- ],
104
- inputs=[species, habitat, region, activity, noise, flow, pollutants, breeding, disturbance]
105
- )
106
-
107
- btn.click(
108
- analyze_biodiversity,
109
- inputs=[species, habitat, region, activity, noise, flow, pollutants, breeding, disturbance],
110
- outputs=output
111
- )
112
 
113
  if __name__ == "__main__":
114
  app.launch()
 
2
  from huggingface_hub import InferenceClient
3
  import os
4
 
 
5
  API_KEY = os.getenv("HF_API_KEY")
 
6
  if not API_KEY:
7
  raise ValueError("⚠️ HF_API_KEY not found. Set it in your environment variables.")
8
 
9
+ # Use a small, free model that actually works
10
+ client = InferenceClient("google/flan-t5-small", token=API_KEY)
11
 
 
12
  def analyze_biodiversity(species, habitat, region, activity, noise, flow, pollutants, breeding, disturbance):
13
  prompt = f"""
14
  You are BioVigilus, an expert AI Ecologist. Create a short, professional Impact Report with emojis.
 
30
  """
31
 
32
  try:
33
+ response = client.text_generation(prompt, max_new_tokens=300)
 
34
  return response[0].generated_text.strip()
35
  except Exception as e:
36
  return f"⚠️ Analysis Failed: {str(e)}"
37
 
38
+ # Minimal Gradio UI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  with gr.Blocks() as app:
40
+ species = gr.Textbox("Species")
41
+ habitat = gr.Textbox("Habitat")
42
+ region = gr.Textbox("Region")
43
+ activity = gr.Textbox("Activity")
44
+ noise = gr.Slider(0,100)
45
+ flow = gr.Slider(0,100)
46
+ disturbance = gr.Slider(0,100)
47
+ pollutants = gr.Textbox("Pollutants")
48
+ breeding = gr.Radio(["Yes","No"], value="No")
49
+ output = gr.Markdown()
50
+ btn = gr.Button("Analyze")
51
+ btn.click(analyze_biodiversity, inputs=[species, habitat, region, activity, noise, flow, pollutants, breeding, disturbance], outputs=output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  if __name__ == "__main__":
54
  app.launch()