alex-abb commited on
Commit
2e73823
·
verified ·
1 Parent(s): 476151f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -28
app.py CHANGED
@@ -1,9 +1,8 @@
1
  import os
2
  import requests
3
- from bs4 import BeautifulSoup
4
 
5
  api_token = os.environ.get("TOKEN")
6
- API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
7
  headers = {"Authorization": f"Bearer {api_token}"}
8
 
9
  def query(payload):
@@ -32,34 +31,27 @@ user
32
  assistant
33
  '''
34
  })
35
-
36
  print("API Response:", output) # Print the full API response
37
 
38
- # Extract the generated text
39
- generated_text = output.get('generated_text', '')
40
- print("Generated Text:", generated_text) # Print the generated text
41
 
42
- # Extract the first non-empty line as the category
43
- lines = [line.strip().lower() for line in generated_text.split('\n') if line.strip()]
44
- if lines:
45
- return lines[0]
46
  return "unknown"
47
 
48
- # Fetch a single post
49
- url = 'https://huggingface.co/posts'
50
- response = requests.get(url)
51
-
52
- if response.status_code == 200:
53
- soup = BeautifulSoup(response.content, 'html.parser')
54
- pl7_element = soup.find(class_='pl-7')
55
- if pl7_element:
56
- pl7_text = pl7_element.text.strip()
57
- print("Post content:")
58
- print(pl7_text)
59
- print("\nAnalyzing sentiment...")
60
- sentiment = analyze_sentiment(pl7_text)
61
- print(f"\nSentiment category: {sentiment}")
62
- else:
63
- print("No post found with class 'pl-7'")
64
- else:
65
- print(f"Error {response.status_code} when retrieving {url}")
 
1
  import os
2
  import requests
 
3
 
4
  api_token = os.environ.get("TOKEN")
5
+ API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat-hf"
6
  headers = {"Authorization": f"Bearer {api_token}"}
7
 
8
  def query(payload):
 
31
  assistant
32
  '''
33
  })
34
+
35
  print("API Response:", output) # Print the full API response
36
 
37
+ if isinstance(output, list) and len(output) > 0:
38
+ generated_text = output[0].get('generated_text', '')
39
+ print("Generated Text:", generated_text) # Print the generated text
40
 
41
+ # Extract the first 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[0]
45
  return "unknown"
46
 
47
+ # Entrée personnalisée pour le test
48
+ custom_post_content = """
49
+ This is a sample post about fine-tuning models for specific tasks.
50
+ It discusses various techniques and best practices for adjusting models.
51
+ """
52
+
53
+ print("Post content:")
54
+ print(custom_post_content)
55
+ print("\nAnalyzing sentiment...")
56
+ sentiment = analyze_sentiment(custom_post_content)
57
+ print(f"\nSentiment category: {sentiment}")