alex-abb commited on
Commit
21a1796
·
verified ·
1 Parent(s): c17b94c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -48
app.py CHANGED
@@ -1,13 +1,12 @@
1
  import os
2
  import requests
 
3
  import gradio as gr
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
-
10
-
11
  def query(payload):
12
  response = requests.post(API_URL, headers=headers, json=payload)
13
  return response.json()
@@ -16,66 +15,60 @@ def analyze_sentiment(text):
16
  output = query({
17
  "inputs": f'''<|begin_of_text|>
18
  <|start_header_id|>system<|end_header_id|>
19
- You're going to deeply analyze the texts I'm going to give you and you're only going to tell me which category they belong to by answering only the words that correspond to the following categories:
20
- For posts that talk about chat models/LLM, return "Chatmodel/LLM"
21
- For posts that talk about image generation models, return "image_generation"
22
- For texts that ask for information from the community, return "questions"
23
- For posts about fine-tuning or model adjustment, return "fine_tuning"
24
- For posts related to ethics and bias in AI, return "ethics_bias"
25
- For posts about datasets and data preparation, return "datasets"
26
- For posts about tools and libraries, return "tools_libraries"
27
- For posts containing tutorials and guides, return "tutorials_guides"
28
- For posts about debugging and problem-solving, return "debugging"
29
- Respond only with the category name, without any additional explanation or text.
30
  <|eot_id|>
31
  <|start_header_id|>user<|end_header_id|>
32
  {text}
33
  <|eot_id|>
34
  <|start_header_id|>assistant<|end_header_id|>
35
-
36
  '''
37
  })
38
 
39
-
40
-
41
  if isinstance(output, list) and len(output) > 0:
42
  response = output[0].get('generated_text', '').strip().lower()
 
 
 
 
 
 
 
43
 
44
- questions = response.count('questions')
45
- ChatmodelLLM = response.count('Chatmodel/LLM')
46
- other = response.count('other')
47
- image_generation = response.count("image_generation")
48
- fine_tuning = response.count("fine_tuning")
49
- ethics_bias = response.count("ethics_bias")
50
- datasets = response.count("datasets")
51
- tools_libraries = response.count("tools_libraries")
52
- tutorials_guides = response.count("tutorials_guides")
53
- debugging = response.count("debugging")
 
 
 
 
 
 
 
 
 
 
 
54
 
55
- if questions == 2:
56
- return 'questions'
57
- elif ChatmodelLLM == 2:
58
- return 'Chat Model/LLM'
59
- elif other == 2:
60
- return "Other"
61
- elif image_generation == 2:
62
- return "Image Generation"
63
- elif fine_tuning == 2:
64
- return "Fine-tuning"
65
- elif ethics_bias == 2:
66
- return "Ethics and Bias"
67
- elif datasets == 2:
68
- return "Datasets"
69
- elif tools_libraries == 2:
70
- return "Tools and Libraries"
71
- elif tutorials_guides == 2:
72
- return "Tutorials and Guides"
73
- elif debugging == 2:
74
- return "Debugging"
75
- else :
76
- return f"Erreur: Réponse ambiguë - '{response}'"
77
 
 
 
 
 
 
 
 
78
 
 
79
  demo = gr.Interface(
80
  fn=analyze_sentiment,
81
  inputs="text",
 
1
  import os
2
  import requests
3
+ from bs4 import BeautifulSoup
4
  import gradio as gr
5
 
6
  api_token = os.environ.get("TOKEN")
7
  API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
8
  headers = {"Authorization": f"Bearer {api_token}"}
9
 
 
 
10
  def query(payload):
11
  response = requests.post(API_URL, headers=headers, json=payload)
12
  return response.json()
 
15
  output = query({
16
  "inputs": f'''<|begin_of_text|>
17
  <|start_header_id|>system<|end_header_id|>
18
+ you are going to analyse the prompt that i'll give to you and tell me if they are either talking about "chat bot", "AI dev",
 
 
 
 
 
 
 
 
 
 
19
  <|eot_id|>
20
  <|start_header_id|>user<|end_header_id|>
21
  {text}
22
  <|eot_id|>
23
  <|start_header_id|>assistant<|end_header_id|>
 
24
  '''
25
  })
26
 
 
 
27
  if isinstance(output, list) and len(output) > 0:
28
  response = output[0].get('generated_text', '').strip().lower()
29
+
30
+ if "chat bot" in response:
31
+ return "chat bot"
32
+ elif "ai dev" in response:
33
+ return "AI dev"
34
+ else:
35
+ return "autre"
36
 
37
+ def scrape_huggingface_posts(url):
38
+ response = requests.get(url)
39
+ soup = BeautifulSoup(response.text, 'html.parser')
40
+
41
+ # Ajustez ce sélecteur selon la structure réelle de la page
42
+ posts = soup.find_all('div', class_='space-y-3 pl-7')
43
+
44
+ extracted_posts = []
45
+ for post in posts:
46
+ # Extrayez les informations pertinentes de chaque post
47
+ title = post.find('h2', class_='post-title').text.strip()
48
+ content = post.find('div', class_='post-content').text.strip()
49
+ author = post.find('span', class_='post-author').text.strip()
50
+
51
+ extracted_posts.append({
52
+ 'title': title,
53
+ 'content': content,
54
+ 'author': author
55
+ })
56
+
57
+ return extracted_posts
58
 
59
+ # Utilisation des fonctions
60
+ url = "https://huggingface.co/posts"
61
+ all_posts = scrape_huggingface_posts(url)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
+ # Analyse de chaque post
64
+ for post in all_posts:
65
+ category = analyze_sentiment(post['content'])
66
+ print(f"Post titre: {post['title']}")
67
+ print(f"Auteur: {post['author']}")
68
+ print(f"Catégorie: {category}")
69
+ print("---")
70
 
71
+ # Interface Gradio (si vous voulez la garder)
72
  demo = gr.Interface(
73
  fn=analyze_sentiment,
74
  inputs="text",