-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Use an official Python runtime as a parent image | ||
FROM python:3.10-slim | ||
|
||
# Set the working directory in the container | ||
WORKDIR /app | ||
|
||
# Install graphviz | ||
RUN apt-get update && apt-get install -y graphviz && rm -rf /var/lib/apt/lists/* | ||
|
||
# Copy the current directory contents into the container at /app | ||
COPY . /app | ||
|
||
# Install any needed packages specified in requirements.txt | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# Define environment variable | ||
ENV NAME World | ||
|
||
# Run app.py when the container launches | ||
CMD ["python", "server.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Flask | ||
graphviz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from flask import Flask, request, send_file | ||
import graphviz | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/graph', methods=['POST']) | ||
def graph(): | ||
# Get the dot format graph from the request | ||
dot_string = request.data.decode() | ||
|
||
try: | ||
# Create a graph from the dot string | ||
dot = graphviz.Source(dot_string) | ||
# Render the graph to a file | ||
output_path = '/tmp/graph' | ||
dot.render(output_path, format='png', cleanup=True) | ||
|
||
# Send the file back | ||
return send_file(output_path + '.png', mimetype='image/png') | ||
except Exception as e: | ||
return str(e), 400 | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=True, host='0.0.0.0', port=8080) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import requests | ||
|
||
# URL of the graph endpoint | ||
url = 'http://localhost:8080/graph' | ||
|
||
# DOT language description of the graph | ||
dot_text = """ | ||
digraph G { | ||
A -> B; | ||
B -> C; | ||
C -> A; | ||
} | ||
""" | ||
|
||
# Send the DOT string as a POST request to the server | ||
response = requests.post(url, data=dot_text) | ||
|
||
# Check if the request was successful | ||
if response.status_code == 200: | ||
# Save the image | ||
with open('output_graph.png', 'wb') as f: | ||
f.write(response.content) | ||
print("Graph image saved as 'output_graph.png'.") | ||
else: | ||
print("Failed to generate graph:", response.text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pyyaml | ||
networkx | ||
requests |