File size: 1,019 Bytes
75384c7
2b42053
75384c7
2b42053
 
 
 
 
 
 
 
 
 
 
 
 
 
75384c7
 
2b42053
75384c7
2b42053
 
75384c7
 
 
 
2b42053
75384c7
2b42053
 
75384c7
 
 
2b42053
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
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM

MODEL_PATH = "lzw1008/ConspEmoLLM-v2"
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
model = AutoModelForCausalLM.from_pretrained(MODEL_PATH)

def classify_conspiracy(text):
    prompt = f"""Human:
Task: Classify the text regarding conspiracy theories or misinformation.
Text: {text}
Assistant:
"""
    inputs = tokenizer(prompt, return_tensors="pt")
    outputs = model.generate(**inputs, max_new_tokens=128)
    result = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return result

demo = gr.Interface(
    fn=classify_conspiracy,
    inputs=gr.Textbox(
        lines=5,
        placeholder="Enter text to classify...",
        label="Input Text"
    ),
    outputs=gr.Textbox(
        lines=10,
        label="Classification Result"
    ),
    title="ConspEmoLLM-v2 API",
    description="Classifies input text for conspiracy theories using the ConspEmoLLM-v2 LLM."
)

if __name__ == "__main__":
    demo.launch()