-
First checkHello I am trying to display animated GIFs with FastApi/Streamlit I actually don't think I should be using streamlit at all. ExampleHere is what I am trying to do, for the moment this does not work, any ideas, guidelines?: from fastapi import FastAPI
import streamlit as st
import pandas as pd
import base64
from fastapi import FastAPI, Response
app = FastAPI()
df = pd.read_csv("/home/ludo915/code/covsco/data/train/all_data_merged/fr/traindfknnimputed.csv")
date = (pd.to_datetime(df["date"].max()) + pd.Timedelta("1 Days")).strftime('%Y-%m-%d')
@app.get("/")
def index():
return {"ok": date}
@app.post("/pm25/")
async def displaypm25():
filepath = "/home/ludo915/code/covsco/forecast/fr/PM2.5-concentration-" +date +".gif"
file_ = open(filepath, "rb")
contents = file_.read()
data_url = base64.b64encode(contents).decode("utf-8")
file_.close()
rt = st.markdown(
f'<img src="data:image/gif;base64,{data_url}" alt="pm25concentration">',
unsafe_allow_html=True,
)
return rt |
Beta Was this translation helpful? Give feedback.
Answered by
Ludo915
May 2, 2021
Replies: 2 comments
-
|
I've managed using: @app.get(
"/pm25/",
response_model=Item,
responses={
200: {
"content": {"image/gif": {}},
"description": "Return the JSON item or an image.",
}
},
)
async def read_item():
filepath = "/home/ludo915/code/covsco/forecast/fr/PM2.5-concentration-" +date +".gif"
return FileResponse(filepath, media_type="image/gif") |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Kludex
-
|
Thanks for reporting back and closing the issue 👍
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've managed using: