Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,13 @@
|
|
1 |
-
import os
|
2 |
import requests
|
3 |
-
import bs4
|
4 |
-
from bs4 import BeautifulSoup
|
5 |
import gradio as gr
|
|
|
|
|
|
|
6 |
|
7 |
-
|
|
|
8 |
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
|
9 |
-
headers = {"Authorization": f"Bearer {
|
10 |
|
11 |
def query(payload):
|
12 |
response = requests.post(API_URL, headers=headers, json=payload)
|
@@ -35,45 +36,37 @@ you are going to analyse the prompt that i'll give to you and tell me if they ar
|
|
35 |
else:
|
36 |
return "autre"
|
37 |
|
38 |
-
def
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
# Ajustez ce sélecteur selon la structure réelle de la page
|
43 |
-
posts = soup.find_all('div', class_='space-y-3 pl-7')
|
44 |
-
|
45 |
-
extracted_posts = []
|
46 |
-
for post in posts:
|
47 |
-
# Extrayez les informations pertinentes de chaque post
|
48 |
-
title = post.find('h2', class_='post-title').text.strip()
|
49 |
-
content = post.find('div', class_='post-content').text.strip()
|
50 |
-
author = post.find('span', class_='post-author').text.strip()
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
fn=analyze_sentiment,
|
75 |
inputs="text",
|
76 |
-
outputs="text"
|
|
|
|
|
77 |
)
|
78 |
|
79 |
-
|
|
|
|
|
1 |
import requests
|
|
|
|
|
2 |
import gradio as gr
|
3 |
+
import bs4
|
4 |
+
from bs4 import BeautifulSoup
|
5 |
+
|
6 |
|
7 |
+
# Configuration de l'API (à ajuster selon votre setup dans le Space)
|
8 |
+
API_TOKEN = "votre_token_api"
|
9 |
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
|
10 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
11 |
|
12 |
def query(payload):
|
13 |
response = requests.post(API_URL, headers=headers, json=payload)
|
|
|
36 |
else:
|
37 |
return "autre"
|
38 |
|
39 |
+
def scrape_and_analyze(url):
|
40 |
+
try:
|
41 |
+
response = requests.get(url)
|
42 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
+
# Ajustez ce sélecteur selon la structure du site cible
|
45 |
+
posts = soup.find_all('div', class_='post')
|
46 |
+
|
47 |
+
categories = {"chat bot": 0, "AI dev": 0, "autre": 0}
|
48 |
+
|
49 |
+
for post in posts:
|
50 |
+
content = post.find('div', class_='content').text.strip() if post.find('div', class_='content') else "Pas de contenu"
|
51 |
+
category = analyze_sentiment(content)
|
52 |
+
categories[category] += 1
|
53 |
+
|
54 |
+
total_posts = sum(categories.values())
|
55 |
+
result = f"Total des posts analysés : {total_posts}\n"
|
56 |
+
result += f"chat bot : {categories['chat bot']}\n"
|
57 |
+
result += f"AI dev : {categories['AI dev']}\n"
|
58 |
+
result += f"autre : {categories['autre']}"
|
59 |
+
|
60 |
+
return result
|
61 |
+
except Exception as e:
|
62 |
+
return f"Une erreur s'est produite : {str(e)}"
|
63 |
|
64 |
+
iface = gr.Interface(
|
65 |
+
fn=scrape_and_analyze,
|
|
|
66 |
inputs="text",
|
67 |
+
outputs="text",
|
68 |
+
title="Analyse de posts de blog",
|
69 |
+
description="Entrez l'URL d'un blog pour analyser ses posts."
|
70 |
)
|
71 |
|
72 |
+
iface.launch()
|