Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,8 +11,7 @@ def query(payload):
|
|
11 |
return response.json()
|
12 |
|
13 |
def analyze_sentiment(pl7_text):
|
14 |
-
|
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"
|
@@ -31,10 +30,19 @@ Respond only with the category name, without any additional explanation or text.
|
|
31 |
<|eot_id|>
|
32 |
<|start_header_id|>assistant<|end_header_id|>
|
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:
|
@@ -50,9 +58,11 @@ if response.status_code == 200:
|
|
50 |
pl7_element = soup.find(class_='pl-7')
|
51 |
if pl7_element:
|
52 |
pl7_text = pl7_element.text.strip()
|
53 |
-
print("
|
|
|
|
|
54 |
sentiment = analyze_sentiment(pl7_text)
|
55 |
-
print(f"
|
56 |
else:
|
57 |
print("No post found with class 'pl-7'")
|
58 |
else:
|
|
|
11 |
return response.json()
|
12 |
|
13 |
def analyze_sentiment(pl7_text):
|
14 |
+
prompt = f'''<|begin_of_text|>
|
|
|
15 |
<|start_header_id|>system<|end_header_id|>
|
16 |
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:
|
17 |
For posts that talk about chat models/LLM, return "Chatmodel/LLM"
|
|
|
30 |
<|eot_id|>
|
31 |
<|start_header_id|>assistant<|end_header_id|>
|
32 |
'''
|
33 |
+
|
34 |
+
print("Sending the following prompt to the API:")
|
35 |
+
print(prompt)
|
36 |
+
|
37 |
+
output = query({"inputs": prompt})
|
38 |
+
|
39 |
+
print("\nAPI Response:")
|
40 |
+
print(output)
|
41 |
|
42 |
if isinstance(output, list) and len(output) > 0:
|
43 |
generated_text = output[0].get('generated_text', '')
|
44 |
+
print("\nGenerated Text:")
|
45 |
+
print(generated_text)
|
46 |
# Extract the last non-empty line as the category
|
47 |
lines = [line.strip().lower() for line in generated_text.split('\n') if line.strip()]
|
48 |
if lines:
|
|
|
58 |
pl7_element = soup.find(class_='pl-7')
|
59 |
if pl7_element:
|
60 |
pl7_text = pl7_element.text.strip()
|
61 |
+
print("Post content (first 100 characters):")
|
62 |
+
print(pl7_text[:100] + "..." if len(pl7_text) > 100 else pl7_text)
|
63 |
+
print("\nAnalyzing post...")
|
64 |
sentiment = analyze_sentiment(pl7_text)
|
65 |
+
print(f"\nSentiment category: {sentiment}")
|
66 |
else:
|
67 |
print("No post found with class 'pl-7'")
|
68 |
else:
|