File size: 1,995 Bytes
00c5b22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import gradio as gr
import requests

# retrieve HF space secrets
auth_key = os.getenv('AUTH_KEY')
api_url = os.getenv('API_URL')
api_port = os.getenv('API_PORT')

HEADERS = {
    'Content-Type': 'application/json'
}

def news_analysis(text):
    try:
        response = requests.post(
            f'{api_url}:{api_port}/news_analysis',
            json={
                'doc_id': '1',
                'text': text,
                'auth_key': auth_key
            },
            headers=HEADERS
        )
        response.raise_for_status()
        return response.json()
    except requests.exceptions.RequestException as error:
        print('Error fetching data from news_analysis:', error)
        raise

def claim_verification(text):
    try:
        response = requests.post(
            f'{api_url}:{api_port}/claim_verification',
            json={
                'doc_id': '1',
                'text': text,
                'auth_key': auth_key
            },
            headers=HEADERS
        )
        response.raise_for_status()
        return response.json()
    except requests.exceptions.RequestException as error:
        print('Error fetching data from claim_verification:', error)
        raise

iface_news_analysis = gr.Interface(
    fn=news_analysis,
    inputs=gr.inputs.Textbox(lines=10, label="News Article Text"),
    outputs=gr.outputs.JSON(label="Classification Result"),
    title="News Analysis",
    description="Classify the domain of a news article and detect major claims."
)

iface_claim_verification = gr.Interface(
    fn=claim_verification,
    inputs=gr.inputs.Textbox(lines=10, label="Claim Text"),
    outputs=gr.outputs.JSON(label="Verification Result"),
    title="Claim Verification",
    description="Verify claims made in a news article."
)

iface = gr.TabbedInterface([iface_news_analysis, iface_claim_verification], ["News Analysis", "Claim Verification"])

# launch the interface
iface.launch(server_name="0.0.0.0", server_port=7860)