Spaces:
Sleeping
Sleeping
Commit
·
00c5b22
1
Parent(s):
ea32375
- Test commit for new gradio app logic (calling the deployed backend directly)
Browse files- Dockerfile +17 -28
- gradio_app.py +67 -0
- requirements.txt +2 -0
Dockerfile
CHANGED
@@ -1,36 +1,25 @@
|
|
1 |
-
#
|
2 |
-
FROM
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
RUN echo "$(cat /run/secrets/DOCKER_HUB_PASSWORD)" | docker login -u "$(cat /run/secrets/DOCKER_HUB_USERNAME)" --password-stdin
|
11 |
-
|
12 |
-
# Stage 2: Use authenticated session to pull the base image and build the application
|
13 |
-
FROM intelligencenoborders/inobo:scinobo-claim-verification
|
14 |
-
|
15 |
-
# Create user and set environment variables
|
16 |
-
RUN useradd -m -u 1000 user && \
|
17 |
-
chown -R user /app
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
PATH=/home/user/.local/bin:$PATH
|
22 |
|
23 |
-
#
|
24 |
-
|
25 |
|
26 |
-
# Expose the port
|
27 |
EXPOSE 7860
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
GRADIO_NUM_PORTS=1 \
|
32 |
-
GRADIO_SERVER_NAME=0.0.0.0 \
|
33 |
-
SYSTEM=spaces
|
34 |
|
35 |
-
# Run
|
36 |
-
CMD ["python", "
|
|
|
1 |
+
# Use the official Python image from the Docker Hub
|
2 |
+
FROM python:3.9-slim
|
3 |
|
4 |
+
# Importing HF space secrets as environment variables
|
5 |
+
ENV AUTH_KEY=${AUTH_KEY}
|
6 |
+
ENV AUTH_KEY=${API_URL}
|
7 |
+
ENV AUTH_KEY=${API_PORT}
|
8 |
|
9 |
+
# Set the working directory in the container
|
10 |
+
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
# Copy the current directory contents into the container at /app
|
13 |
+
COPY . /app
|
|
|
14 |
|
15 |
+
# Install any needed packages specified in requirements.txt
|
16 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
17 |
|
18 |
+
# Expose the port the app runs on
|
19 |
EXPOSE 7860
|
20 |
|
21 |
+
# Define environment variable to avoid buffering in logs
|
22 |
+
ENV PYTHONUNBUFFERED=1
|
|
|
|
|
|
|
23 |
|
24 |
+
# Run the application
|
25 |
+
CMD ["python", "gradio_app.py"]
|
gradio_app.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
import requests
|
4 |
+
|
5 |
+
# retrieve HF space secrets
|
6 |
+
auth_key = os.getenv('AUTH_KEY')
|
7 |
+
api_url = os.getenv('API_URL')
|
8 |
+
api_port = os.getenv('API_PORT')
|
9 |
+
|
10 |
+
HEADERS = {
|
11 |
+
'Content-Type': 'application/json'
|
12 |
+
}
|
13 |
+
|
14 |
+
def news_analysis(text):
|
15 |
+
try:
|
16 |
+
response = requests.post(
|
17 |
+
f'{api_url}:{api_port}/news_analysis',
|
18 |
+
json={
|
19 |
+
'doc_id': '1',
|
20 |
+
'text': text,
|
21 |
+
'auth_key': auth_key
|
22 |
+
},
|
23 |
+
headers=HEADERS
|
24 |
+
)
|
25 |
+
response.raise_for_status()
|
26 |
+
return response.json()
|
27 |
+
except requests.exceptions.RequestException as error:
|
28 |
+
print('Error fetching data from news_analysis:', error)
|
29 |
+
raise
|
30 |
+
|
31 |
+
def claim_verification(text):
|
32 |
+
try:
|
33 |
+
response = requests.post(
|
34 |
+
f'{api_url}:{api_port}/claim_verification',
|
35 |
+
json={
|
36 |
+
'doc_id': '1',
|
37 |
+
'text': text,
|
38 |
+
'auth_key': auth_key
|
39 |
+
},
|
40 |
+
headers=HEADERS
|
41 |
+
)
|
42 |
+
response.raise_for_status()
|
43 |
+
return response.json()
|
44 |
+
except requests.exceptions.RequestException as error:
|
45 |
+
print('Error fetching data from claim_verification:', error)
|
46 |
+
raise
|
47 |
+
|
48 |
+
iface_news_analysis = gr.Interface(
|
49 |
+
fn=news_analysis,
|
50 |
+
inputs=gr.inputs.Textbox(lines=10, label="News Article Text"),
|
51 |
+
outputs=gr.outputs.JSON(label="Classification Result"),
|
52 |
+
title="News Analysis",
|
53 |
+
description="Classify the domain of a news article and detect major claims."
|
54 |
+
)
|
55 |
+
|
56 |
+
iface_claim_verification = gr.Interface(
|
57 |
+
fn=claim_verification,
|
58 |
+
inputs=gr.inputs.Textbox(lines=10, label="Claim Text"),
|
59 |
+
outputs=gr.outputs.JSON(label="Verification Result"),
|
60 |
+
title="Claim Verification",
|
61 |
+
description="Verify claims made in a news article."
|
62 |
+
)
|
63 |
+
|
64 |
+
iface = gr.TabbedInterface([iface_news_analysis, iface_claim_verification], ["News Analysis", "Claim Verification"])
|
65 |
+
|
66 |
+
# launch the interface
|
67 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio==3.0.10
|
2 |
+
requests==2.28.1
|