Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ __import__('pysqlite3')
|
|
9 |
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')
|
10 |
|
11 |
from crewai import Agent, Task, Crew
|
12 |
-
from
|
13 |
|
14 |
def generate_jingle(theme):
|
15 |
# Hugging Face API Key handling
|
@@ -19,20 +19,21 @@ def generate_jingle(theme):
|
|
19 |
if not hf_api_key.startswith("hf_"):
|
20 |
return "Error: Invalid Hugging Face API token. It should start with 'hf_'. Please check and update the token in Space secrets."
|
21 |
|
22 |
-
# LLM setup with
|
23 |
try:
|
24 |
-
llm =
|
25 |
-
|
26 |
huggingfacehub_api_token=hf_api_key,
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
)
|
33 |
# Test the endpoint
|
34 |
try:
|
35 |
test_response = llm.invoke("Test connection to Hugging Face API")
|
|
|
36 |
except Exception as test_e:
|
37 |
return f"Warning: Test API call failed: {str(test_e)}. Proceeding anyway, but jingle generation may fail."
|
38 |
except Exception as e:
|
|
|
9 |
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')
|
10 |
|
11 |
from crewai import Agent, Task, Crew
|
12 |
+
from langchain_community.llms import HuggingFaceHub
|
13 |
|
14 |
def generate_jingle(theme):
|
15 |
# Hugging Face API Key handling
|
|
|
19 |
if not hf_api_key.startswith("hf_"):
|
20 |
return "Error: Invalid Hugging Face API token. It should start with 'hf_'. Please check and update the token in Space secrets."
|
21 |
|
22 |
+
# LLM setup with HuggingFaceHub
|
23 |
try:
|
24 |
+
llm = HuggingFaceHub(
|
25 |
+
repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
26 |
huggingfacehub_api_token=hf_api_key,
|
27 |
+
model_kwargs={
|
28 |
+
"max_new_tokens": 500,
|
29 |
+
"temperature": 0.7,
|
30 |
+
"top_p": 0.9
|
31 |
+
}
|
32 |
)
|
33 |
# Test the endpoint
|
34 |
try:
|
35 |
test_response = llm.invoke("Test connection to Hugging Face API")
|
36 |
+
return f"Hugging Face API connection successful! Response: {test_response[:100]}...\n\nStarting jingle generation..."
|
37 |
except Exception as test_e:
|
38 |
return f"Warning: Test API call failed: {str(test_e)}. Proceeding anyway, but jingle generation may fail."
|
39 |
except Exception as e:
|