File size: 2,991 Bytes
73f9174
95f7ff3
f07cabc
50639ab
2e937f5
4d9b3ae
2e937f5
 
f07cabc
 
57d46c6
6eed6c8
 
57d46c6
f07cabc
6eed6c8
f07cabc
 
 
73f9174
 
 
 
 
 
 
 
 
 
f07cabc
 
 
 
 
b11c8cd
6eed6c8
2e73823
f07cabc
 
2e73823
f07cabc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95f7ff3
f07cabc
 
 
 
 
2e73823
f07cabc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
import requests
import gradio as gr

api_token = os.environ.get("TOKEN")
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
headers = {"Authorization": f"Bearer {api_token}"}



def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    return response.json()

def analyze_sentiment(text):
    output = query({
        "inputs": f'''<|begin_of_text|>
<|start_header_id|>system<|end_header_id|>
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:
For posts that talk about chat models/LLM, return "Chatmodel/LLM"
For posts that talk about image generation models, return "image_generation"
For texts that ask for information from the community, return "questions"
For posts about fine-tuning or model adjustment, return "fine_tuning"
For posts related to ethics and bias in AI, return "ethics_bias"
For posts about datasets and data preparation, return "datasets"
For posts about tools and libraries, return "tools_libraries"
For posts containing tutorials and guides, return "tutorials_guides"
For posts about debugging and problem-solving, return "debugging"
Respond only with the category name, without any additional explanation or text.
<|eot_id|>
<|start_header_id|>user<|end_header_id|>
{text}
<|eot_id|>
<|start_header_id|>assistant<|end_header_id|>
'''
    })



    if isinstance(output, list) and len(output) > 0:
        response = output[0].get('generated_text', '').strip().lower()

        questions = response.count('questions')
        ChatmodelLLM = response.count('Chatmodel/LLM')
        other = response.count('other')
        image_generation = response.count("image_generation")
        fine_tuning = response.count("fine_tuning")
        ethics_bias = response.count("ethics_bias")
        datasets = response.count("datasets")
        tools_libraries = response.count("tools_libraries")
        tutorials_guides = response.count("tutorials_guides")
        debugging = response.count("debugging")

        if questions == 2:
            return 'questions'
        elif ChatmodelLLM == 2:
            return 'Chat Model/LLM'
        elif other == 2:
            return "Other"
        elif image_generation == 2:
            return "Image Generation"
        elif fine_tuning == 2:
            return "Fine-tuning"
        elif ethics_bias == 2:
            return "Ethics and Bias"
        elif datasets == 2:
            return "Datasets"
        elif tools_libraries == 2:
            return "Tools and Libraries"
        elif tutorials_guides == 2:
            return "Tutorials and Guides"
        elif debugging == 2:
            return "Debugging"
        else :
            return f"Erreur: Réponse ambiguë - '{response}'"


demo = gr.Interface(
    fn=analyze_sentiment,
    inputs="text",
    outputs="text"
)

demo.launch()