Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import os
|
2 |
import requests
|
3 |
-
from collections import Counter
|
4 |
from bs4 import BeautifulSoup
|
5 |
|
6 |
api_token = os.environ.get("TOKEN")
|
@@ -13,7 +12,8 @@ def query(payload):
|
|
13 |
|
14 |
def analyze_sentiment(pl7_text):
|
15 |
output = query({
|
16 |
-
"inputs": f'''
|
|
|
17 |
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:
|
18 |
For posts that talk about chat models/LLM, return "Chatmodel/LLM"
|
19 |
For posts that talk about image generation models, return "image_generation"
|
@@ -25,37 +25,40 @@ For posts about tools and libraries, return "tools_libraries"
|
|
25 |
For posts containing tutorials and guides, return "tutorials_guides"
|
26 |
For posts about debugging and problem-solving, return "debugging"
|
27 |
Respond only with the category name, without any additional explanation or text.
|
28 |
-
|
29 |
-
|
30 |
-
Analyze the following text:
|
31 |
{pl7_text}
|
32 |
-
|
|
|
33 |
'''
|
34 |
})
|
35 |
|
|
|
|
|
36 |
if isinstance(output, list) and len(output) > 0:
|
37 |
generated_text = output[0].get('generated_text', '')
|
|
|
38 |
# Extract the last non-empty line as the category
|
39 |
lines = [line.strip().lower() for line in generated_text.split('\n') if line.strip()]
|
40 |
if lines:
|
41 |
return lines[-1]
|
42 |
return "unknown"
|
43 |
|
|
|
44 |
url = 'https://huggingface.co/posts'
|
45 |
response = requests.get(url)
|
46 |
|
47 |
if response.status_code == 200:
|
48 |
soup = BeautifulSoup(response.content, 'html.parser')
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
sentiment = analyze_sentiment(
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
print(f"{category} = {count}")
|
60 |
else:
|
61 |
print(f"Error {response.status_code} when retrieving {url}")
|
|
|
1 |
import os
|
2 |
import requests
|
|
|
3 |
from bs4 import BeautifulSoup
|
4 |
|
5 |
api_token = os.environ.get("TOKEN")
|
|
|
12 |
|
13 |
def analyze_sentiment(pl7_text):
|
14 |
output = query({
|
15 |
+
"inputs": f'''<|begin_of_text|>
|
16 |
+
<|start_header_id|>system<|end_header_id|>
|
17 |
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:
|
18 |
For posts that talk about chat models/LLM, return "Chatmodel/LLM"
|
19 |
For posts that talk about image generation models, return "image_generation"
|
|
|
25 |
For posts containing tutorials and guides, return "tutorials_guides"
|
26 |
For posts about debugging and problem-solving, return "debugging"
|
27 |
Respond only with the category name, without any additional explanation or text.
|
28 |
+
<|eot_id|>
|
29 |
+
<|start_header_id|>user<|end_header_id|>
|
|
|
30 |
{pl7_text}
|
31 |
+
<|eot_id|>
|
32 |
+
<|start_header_id|>assistant<|end_header_id|>
|
33 |
'''
|
34 |
})
|
35 |
|
36 |
+
print("API Response:", output) # Print the full API response
|
37 |
+
|
38 |
if isinstance(output, list) and len(output) > 0:
|
39 |
generated_text = output[0].get('generated_text', '')
|
40 |
+
print("Generated Text:", generated_text) # Print the generated text
|
41 |
# Extract the last non-empty line as the category
|
42 |
lines = [line.strip().lower() for line in generated_text.split('\n') if line.strip()]
|
43 |
if lines:
|
44 |
return lines[-1]
|
45 |
return "unknown"
|
46 |
|
47 |
+
# Fetch a single post
|
48 |
url = 'https://huggingface.co/posts'
|
49 |
response = requests.get(url)
|
50 |
|
51 |
if response.status_code == 200:
|
52 |
soup = BeautifulSoup(response.content, 'html.parser')
|
53 |
+
pl7_element = soup.find(class_='pl-7')
|
54 |
+
if pl7_element:
|
55 |
+
pl7_text = pl7_element.text.strip()
|
56 |
+
print("Post content:")
|
57 |
+
print(pl7_text)
|
58 |
+
print("\nAnalyzing sentiment...")
|
59 |
+
sentiment = analyze_sentiment(pl7_text)
|
60 |
+
print(f"\nSentiment category: {sentiment}")
|
61 |
+
else:
|
62 |
+
print("No post found with class 'pl-7'")
|
|
|
63 |
else:
|
64 |
print(f"Error {response.status_code} when retrieving {url}")
|