Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,11 +2,21 @@ import streamlit as st
|
|
| 2 |
import requests
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def fetch_plant_data(plant_name):
|
| 11 |
url = f"https://openfarm.cc/api/v1/crops?filter={plant_name}"
|
| 12 |
response = requests.get(url)
|
|
|
|
| 2 |
import requests
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
+
# Cache the AI models to avoid reloading them on every interaction
|
| 6 |
+
@st.cache_resource
|
| 7 |
+
def load_qa_model():
|
| 8 |
+
return pipeline("question-answering", model="distilbert-base-cased-distilled-squad", framework="pt")
|
| 9 |
|
| 10 |
+
@st.cache_resource
|
| 11 |
+
def load_text_generation_model():
|
| 12 |
+
return pipeline("text-generation", model="gpt2", framework="pt")
|
| 13 |
+
|
| 14 |
+
# Initialize the AI models
|
| 15 |
+
qa_pipeline = load_qa_model()
|
| 16 |
+
text_generation_pipeline = load_text_generation_model()
|
| 17 |
+
|
| 18 |
+
# Cache the plant data fetching function to avoid redundant API calls
|
| 19 |
+
@st.cache_data(ttl=3600) # Cache for 1 hour
|
| 20 |
def fetch_plant_data(plant_name):
|
| 21 |
url = f"https://openfarm.cc/api/v1/crops?filter={plant_name}"
|
| 22 |
response = requests.get(url)
|