File size: 2,827 Bytes
73f9174
95f7ff3
b6827ba
50639ab
2e937f5
bcda593
2e937f5
 
57d46c6
f34d7d5
 
 
 
 
 
 
57d46c6
b6827ba
d031db7
8ac912b
b6827ba
73f9174
 
 
 
 
 
 
 
 
 
8ac912b
 
b6827ba
8ac912b
 
b11c8cd
d031db7
f34d7d5
d031db7
 
f34d7d5
 
 
 
 
 
b6827ba
 
7e87179
f34d7d5
 
95f7ff3
8ac912b
95f7ff3
 
 
 
 
8ac912b
 
 
f34d7d5
 
 
7e87179
 
8ac912b
 
95f7ff3
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import requests
from bs4 import BeautifulSoup

api_token = os.environ.get("TOKEN")
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat-hf"
headers = {"Authorization": f"Bearer {api_token}"}

def query(payload):
    try:
        response = requests.post(API_URL, headers=headers, json=payload)
        response.raise_for_status()  # Raise an exception for bad status codes
        return response.json()
    except requests.exceptions.RequestException as e:
        print(f"Error making request to API: {e}")
        return None

def analyze_sentiment(pl7_text):
    prompt = f'''<|begin_of_text|>
<|start_header_id|>system<|end_header_id|>
You're going to deeply analyze the text I'm going to give you and you're only going to tell me which category it belongs to by answering only the words that correspond to the following categories:
For posts that talk about chat models/LLM, return "Chatmodel/LLM"
For posts that talk about image generation models, return "image_generation"
For texts that ask for information from the community, return "questions"
For posts about fine-tuning or model adjustment, return "fine_tuning"
For posts related to ethics and bias in AI, return "ethics_bias"
For posts about datasets and data preparation, return "datasets"
For posts about tools and libraries, return "tools_libraries"
For posts containing tutorials and guides, return "tutorials_guides"
For posts about debugging and problem-solving, return "debugging"
Respond only with the category name, without any additional explanation or text.
<|eot_id|>
<|start_header_id|>user<|end_header_id|>
{pl7_text}
<|eot_id|>
<|start_header_id|>assistant<|end_header_id|>
'''
    
    print("Sending request to API...")
    output = query({"inputs": prompt})
    
    if output is None:
        return "Error: Failed to get response from API"
    
    print("Raw API response:")
    print(output)
    
    if isinstance(output, list) and len(output) > 0:
        generated_text = output[0].get('generated_text', '')
        return generated_text.strip()
    else:
        return "Error: Unexpected response format from API"

# Fetch a single post
url = 'https://huggingface.co/posts'
response = requests.get(url)

if response.status_code == 200:
    soup = BeautifulSoup(response.content, 'html.parser')
    pl7_element = soup.find(class_='pl-7')
    if pl7_element:
        pl7_text = pl7_element.text.strip()
        print("Post content (first 100 characters):")
        print(pl7_text[:100] + "..." if len(pl7_text) > 100 else pl7_text)
        print("\nAnalyzing post...")
        llm_response = analyze_sentiment(pl7_text)
        print(f"\nLLM Response:\n{llm_response}")
    else:
        print("No post found with class 'pl-7'")
else:
    print(f"Error {response.status_code} when retrieving {url}")