Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,15 +5,20 @@ from langchain.agents import initialize_agent, Tool
|
|
| 5 |
from langchain.prompts import PromptTemplate
|
| 6 |
from langchain_huggingface import HuggingFaceEndpoint
|
| 7 |
|
| 8 |
-
#
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
prompts = {
|
| 12 |
-
"default": "{{user_input}}" # Corrected: No pipe needed
|
| 13 |
-
}
|
| 14 |
-
prompt_template = PromptTemplate(template=prompts["default"], input_variables=["user_input"])
|
| 15 |
|
| 16 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
# Define tools (motivational quote tool)
|
|
|
|
| 5 |
from langchain.prompts import PromptTemplate
|
| 6 |
from langchain_huggingface import HuggingFaceEndpoint
|
| 7 |
|
| 8 |
+
# Load environment variables (Make sure these are set in your Space Secrets)
|
| 9 |
+
HF_API_KEY = os.environ.get("HUGGINGFACEHUB_API_TOKEN")
|
| 10 |
+
HF_MODEL_ID = os.environ.get("HF_MODEL_ID", "google/flan-t5-xxl") # Default model if env var not set
|
| 11 |
|
| 12 |
+
# ... (Rest of your code: prompts, tools, etc.)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# Initialize LLM (Now HF_MODEL_ID is defined)
|
| 15 |
+
llm = HuggingFaceEndpoint(
|
| 16 |
+
repo_id=HF_MODEL_ID, # This will now work
|
| 17 |
+
temperature=0.7,
|
| 18 |
+
max_new_tokens=512,
|
| 19 |
+
huggingfacehub_api_token=HF_API_KEY,
|
| 20 |
+
task="text-generation",
|
| 21 |
+
)
|
| 22 |
|
| 23 |
|
| 24 |
# Define tools (motivational quote tool)
|