Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,15 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
|
3 |
-
def
|
4 |
-
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
demo.launch()
|
|
|
1 |
+
import os, gradio as gr, openai
|
2 |
+
openai.api_key = os.getenv("DEEPSEEK_API_KEY")
|
3 |
+
def analyze_env(temperature, light, soil_humidity):
|
4 |
+
msg = [
|
5 |
+
{"role": "system", "content": "You are a plant care assistant."},
|
6 |
+
{"role": "user", "content": f"Temperature: {temperature}°C, Light: {light} lux, Soil Humidity: {soil_humidity}%."}
|
7 |
+
]
|
8 |
+
resp = openai.ChatCompletion.create(model="deepseek-chat", messages=msg, temperature=0.7)
|
9 |
+
return resp.choices[0].message.content
|
10 |
+
demo = gr.Interface(fn=analyze_env,
|
11 |
+
inputs=[gr.Number(label="Temperature (°C)"), gr.Number(label="Light (lux)"), gr.Number(label="Soil Humidity (%)")],
|
12 |
+
outputs="text",
|
13 |
+
title="植物环境分析"
|
14 |
+
)
|
15 |
demo.launch()
|