File size: 2,513 Bytes
8e15a23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
85
86
87
import gradio as gr
import os
import json

with open('results.json', 'r') as f:
    results_data = json.load(f)

with open('sarcasm_data.json', 'r') as f:
    sarcasm_data = json.load(f)

def get_dialogues_and_result(id):
    pred = next((item for item in results_data if item['id'] == id), None)
    if not pred:
        return f"ID {id} not found in results.json"
    
    sarcasm_info = sarcasm_data.get(id)
    if not sarcasm_info:
        return f"ID {id} not found in sarcasm_data.json"
    
    utterance = f"{sarcasm_info['speaker']}: {sarcasm_info['utterance']}"
    context = "\n".join(
        f"{speaker}: {line}" for speaker, line in zip(sarcasm_info['context_speakers'], sarcasm_info['context'])
    )
    
    output = {
        "id": id,
        "utterance": utterance,
        "context": context,
        "ground_truth": int(sarcasm_info['sarcasm']),
        "pred": pred['sarcasm']
    }
    
    return output

def analyze_videos(utterance_filename):
    utterance_id = os.path.splitext(os.path.basename(utterance_filename))[0]
    output = get_dialogues_and_result(utterance_id)
    
    return (
        output["context"],
        output["utterance"],
        output["ground_truth"],
        output["pred"]
    )

def custom_css():
    return """
    .gradio-heading {
        text-align: center;
        color: #0056b3;
        font-size: 28px;
        font-weight: bold;
        margin-bottom: 20px;
    }
    """

css_style = custom_css()

with gr.Blocks(css=css_style) as interface:
    gr.Markdown("<div class='gradio-heading'>Sarcasm Detection</div>")
    with gr.Row():
        with gr.Column(scale=1):
            context_video_input = gr.Video(label="Upload Context Video")
            punchline_video_input = gr.Video(label="Upload Punchline Video")
        with gr.Column(scale=2):
            context_dialogue_output = gr.Textbox(label="Context Dialogues")
            punchline_dialogue_output = gr.Textbox(label="Punchline Dialogue")
            with gr.Column():
                punchline_sarcasm_true = gr.Label(label="Ground Truth")
                punchline_sarcasm_pred = gr.Label(label="Sarcasm Detected")

    submit_button = gr.Button("Submit")

    submit_button.click(
        fn=analyze_videos,
        inputs=[punchline_video_input],
        outputs=[
            context_dialogue_output,
            punchline_dialogue_output,
            punchline_sarcasm_true,
            punchline_sarcasm_pred
        ]
    )

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