Spaces:
Sleeping
Sleeping
Commit
·
d357382
1
Parent(s):
e182303
updated streamlit file
Browse files- .ipynb_checkpoints/start-checkpoint.sh +8 -2
- .ipynb_checkpoints/streamlit_app-checkpoint.py +16 -16
- start.sh +8 -2
- streamlit_app.py +16 -16
.ipynb_checkpoints/start-checkpoint.sh
CHANGED
@@ -1,7 +1,13 @@
|
|
1 |
#!/bin/bash
|
2 |
|
3 |
# Start FastAPI
|
4 |
-
|
5 |
|
6 |
# Start Streamlit
|
7 |
-
streamlit run streamlit_app.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
#!/bin/bash
|
2 |
|
3 |
# Start FastAPI
|
4 |
+
uvicorn app:app --host 0.0.0.0 --port 8502 &
|
5 |
|
6 |
# Start Streamlit
|
7 |
+
streamlit run streamlit_app.py \
|
8 |
+
--server.port=7860 \
|
9 |
+
--server.address=0.0.0.0 \
|
10 |
+
--server.headless true \
|
11 |
+
--server.enableCORS false \
|
12 |
+
--server.enableXsrfProtection false \
|
13 |
+
--server.fileWatcherType none
|
.ipynb_checkpoints/streamlit_app-checkpoint.py
CHANGED
@@ -6,16 +6,16 @@ import torch
|
|
6 |
import io
|
7 |
|
8 |
|
9 |
-
@st.cache_resource
|
10 |
-
def load_model():
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
model, processor = load_model()
|
19 |
|
20 |
st.title("Image Captioning with Fine-Tuned BLiPv2 Model")
|
21 |
|
@@ -25,16 +25,16 @@ if uploaded_file is not None:
|
|
25 |
image = Image.open(uploaded_file)
|
26 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
27 |
|
28 |
-
|
29 |
print("Sending API request")
|
30 |
-
|
31 |
-
|
32 |
|
33 |
-
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
|
39 |
st.write("Generated Caption:")
|
40 |
st.write(f"**{caption}**")
|
|
|
6 |
import io
|
7 |
|
8 |
|
9 |
+
# @st.cache_resource
|
10 |
+
# def load_model():
|
11 |
+
# model = Blip2ForConditionalGeneration.from_pretrained("ybelkada/blip2-opt-2.7b-fp16-sharded")
|
12 |
+
# model.load_adapter('blip-cpu-model')
|
13 |
+
# processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
|
14 |
+
# device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
15 |
+
# model.to(device)
|
16 |
+
# return model, processor
|
17 |
|
18 |
+
# model, processor = load_model()
|
19 |
|
20 |
st.title("Image Captioning with Fine-Tuned BLiPv2 Model")
|
21 |
|
|
|
25 |
image = Image.open(uploaded_file)
|
26 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
27 |
|
28 |
+
files = {"file": uploaded_file.getvalue()}
|
29 |
print("Sending API request")
|
30 |
+
response = requests.post("http://0.0.0.0:8502/generate-caption/", files=files)
|
31 |
+
caption = response.json().get("caption")
|
32 |
|
33 |
+
# inputs = processor(images=image, return_tensors="pt").to(device, torch.float16)
|
34 |
|
35 |
+
# with torch.no_grad():
|
36 |
+
# caption_ids = model.generate(**inputs, max_length=128)
|
37 |
+
# caption = processor.decode(caption_ids[0], skip_special_tokens=True)
|
38 |
|
39 |
st.write("Generated Caption:")
|
40 |
st.write(f"**{caption}**")
|
start.sh
CHANGED
@@ -1,7 +1,13 @@
|
|
1 |
#!/bin/bash
|
2 |
|
3 |
# Start FastAPI
|
4 |
-
|
5 |
|
6 |
# Start Streamlit
|
7 |
-
streamlit run streamlit_app.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
#!/bin/bash
|
2 |
|
3 |
# Start FastAPI
|
4 |
+
uvicorn app:app --host 0.0.0.0 --port 8502 &
|
5 |
|
6 |
# Start Streamlit
|
7 |
+
streamlit run streamlit_app.py \
|
8 |
+
--server.port=7860 \
|
9 |
+
--server.address=0.0.0.0 \
|
10 |
+
--server.headless true \
|
11 |
+
--server.enableCORS false \
|
12 |
+
--server.enableXsrfProtection false \
|
13 |
+
--server.fileWatcherType none
|
streamlit_app.py
CHANGED
@@ -6,16 +6,16 @@ import torch
|
|
6 |
import io
|
7 |
|
8 |
|
9 |
-
@st.cache_resource
|
10 |
-
def load_model():
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
model, processor = load_model()
|
19 |
|
20 |
st.title("Image Captioning with Fine-Tuned BLiPv2 Model")
|
21 |
|
@@ -25,16 +25,16 @@ if uploaded_file is not None:
|
|
25 |
image = Image.open(uploaded_file)
|
26 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
27 |
|
28 |
-
|
29 |
print("Sending API request")
|
30 |
-
|
31 |
-
|
32 |
|
33 |
-
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
|
39 |
st.write("Generated Caption:")
|
40 |
st.write(f"**{caption}**")
|
|
|
6 |
import io
|
7 |
|
8 |
|
9 |
+
# @st.cache_resource
|
10 |
+
# def load_model():
|
11 |
+
# model = Blip2ForConditionalGeneration.from_pretrained("ybelkada/blip2-opt-2.7b-fp16-sharded")
|
12 |
+
# model.load_adapter('blip-cpu-model')
|
13 |
+
# processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
|
14 |
+
# device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
15 |
+
# model.to(device)
|
16 |
+
# return model, processor
|
17 |
|
18 |
+
# model, processor = load_model()
|
19 |
|
20 |
st.title("Image Captioning with Fine-Tuned BLiPv2 Model")
|
21 |
|
|
|
25 |
image = Image.open(uploaded_file)
|
26 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
27 |
|
28 |
+
files = {"file": uploaded_file.getvalue()}
|
29 |
print("Sending API request")
|
30 |
+
response = requests.post("http://0.0.0.0:8502/generate-caption/", files=files)
|
31 |
+
caption = response.json().get("caption")
|
32 |
|
33 |
+
# inputs = processor(images=image, return_tensors="pt").to(device, torch.float16)
|
34 |
|
35 |
+
# with torch.no_grad():
|
36 |
+
# caption_ids = model.generate(**inputs, max_length=128)
|
37 |
+
# caption = processor.decode(caption_ids[0], skip_special_tokens=True)
|
38 |
|
39 |
st.write("Generated Caption:")
|
40 |
st.write(f"**{caption}**")
|