Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import os
|
2 |
import requests
|
3 |
from collections import Counter
|
|
|
4 |
|
5 |
api_token = os.environ.get("TOKEN")
|
6 |
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat-hf"
|
@@ -10,10 +11,10 @@ def query(payload):
|
|
10 |
response = requests.post(API_URL, headers=headers, json=payload)
|
11 |
return response.json()
|
12 |
|
13 |
-
def analyze_sentiment(
|
14 |
output = query({
|
15 |
"inputs": f'''<s>[INST] <<SYS>>
|
16 |
-
You're going to deeply analyze the
|
17 |
For posts that talk about chat models/LLM, return "Chatmodel/LLM"
|
18 |
For posts that talk about image generation models, return "image_generation"
|
19 |
For texts that ask for information from the community, return "questions"
|
@@ -27,20 +28,23 @@ Respond only with the category name, without any additional explanation or text.
|
|
27 |
<</SYS>>
|
28 |
|
29 |
Analyze the following text:
|
30 |
-
{
|
31 |
[/INST]
|
32 |
'''
|
33 |
})
|
34 |
|
35 |
-
if isinstance(output, list) and len(output) > 0
|
36 |
-
|
|
|
|
|
|
|
|
|
37 |
return "unknown"
|
38 |
|
39 |
url = 'https://huggingface.co/posts'
|
40 |
response = requests.get(url)
|
41 |
|
42 |
if response.status_code == 200:
|
43 |
-
from bs4 import BeautifulSoup
|
44 |
soup = BeautifulSoup(response.content, 'html.parser')
|
45 |
pl7_elements = soup.find_all(class_='pl-7')
|
46 |
pl7_texts = [element.text.strip() for element in pl7_elements]
|
|
|
1 |
import os
|
2 |
import requests
|
3 |
from collections import Counter
|
4 |
+
from bs4 import BeautifulSoup
|
5 |
|
6 |
api_token = os.environ.get("TOKEN")
|
7 |
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat-hf"
|
|
|
11 |
response = requests.post(API_URL, headers=headers, json=payload)
|
12 |
return response.json()
|
13 |
|
14 |
+
def analyze_sentiment(pl7_text):
|
15 |
output = query({
|
16 |
"inputs": f'''<s>[INST] <<SYS>>
|
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"
|
20 |
For texts that ask for information from the community, return "questions"
|
|
|
28 |
<</SYS>>
|
29 |
|
30 |
Analyze the following text:
|
31 |
+
{pl7_text}
|
32 |
[/INST]
|
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 |
pl7_elements = soup.find_all(class_='pl-7')
|
50 |
pl7_texts = [element.text.strip() for element in pl7_elements]
|