swapniild1601 commited on
Commit
8030fe1
·
verified ·
1 Parent(s): d2e52bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
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 langchain_huggingface import HuggingFaceEndpoint
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 Mistral 7B
23
  try:
24
- llm = HuggingFaceEndpoint(
25
- endpoint_url="https://api-inference.huggingface.co/models/mixtral-8x7b-instruct-v0.1",
26
  huggingfacehub_api_token=hf_api_key,
27
- max_new_tokens=500,
28
- temperature=0.7,
29
- top_p=0.9,
30
- retry_on_rate_limit=True,
31
- timeout=30
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: