alex-abb commited on
Commit
7e87179
·
verified ·
1 Parent(s): d031db7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -18
app.py CHANGED
@@ -31,23 +31,12 @@ Respond only with the category name, without any additional explanation or text.
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:
49
- return lines[-1]
50
- return "unknown"
51
 
52
  # Fetch a single post
53
  url = 'https://huggingface.co/posts'
@@ -58,11 +47,9 @@ if response.status_code == 200:
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:
 
31
  <|start_header_id|>assistant<|end_header_id|>
32
  '''
33
 
 
 
 
34
  output = query({"inputs": prompt})
35
 
 
 
 
36
  if isinstance(output, list) and len(output) > 0:
37
  generated_text = output[0].get('generated_text', '')
38
+ return generated_text.strip()
39
+ return "Error: No response from the model"
 
 
 
 
 
40
 
41
  # Fetch a single post
42
  url = 'https://huggingface.co/posts'
 
47
  pl7_element = soup.find(class_='pl-7')
48
  if pl7_element:
49
  pl7_text = pl7_element.text.strip()
50
+ print("Analyzing post...")
51
+ llm_response = analyze_sentiment(pl7_text)
52
+ print(f"\nLLM Response:\n{llm_response}")
 
 
53
  else:
54
  print("No post found with class 'pl-7'")
55
  else: