Spaces:
Running
Running
| import os | |
| from huggingface_hub import InferenceClient | |
| # Initialize client without provider (Hugging Face handles routing) | |
| client = InferenceClient( | |
| model="Qwen/Qwen2.5-7B-Instruct", | |
| token=os.environ.get("HF_TOKEN") # Make sure HF_TOKEN is set in Secrets | |
| ) | |
| def analyze_data(prompt): | |
| """ | |
| Use chat completions API to generate insights from raw search data | |
| """ | |
| try: | |
| # Format prompt as a chat message | |
| messages = [ | |
| { | |
| "role": "user", | |
| "content": prompt | |
| } | |
| ] | |
| # Get response from LLM | |
| completion = client.chat.completions.create( | |
| messages=messages, | |
| max_tokens=4096 # Control response length | |
| ) | |
| # Return only the content part of the response | |
| return completion.choices[0].message.content | |
| except Exception as e: | |
| return f"LLM generation failed: {str(e)}" |