Skip to content

Commit f6a3c55

Browse files
2 parents ead5498 + 14b10ba commit f6a3c55

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ pip install -r requirements.txt
9393
### 5. (Optional) Adding a new model
9494
If you're adding a new model to the project, please request write access for caching of the model. If not, you can also just add the train code locally
9595
96-
### 6. (Optional) Updatign the report PDF
96+
### 6. (Optional) Updating the report PDF
9797
To update the report PDF, you may look into `report/main.tex` and make your updates there, and if you have the `make` tool as well as `pdflatex` installed, you may do the following commands to re-generate the PDF.
9898
9999
```bash
100100
cd reports
101101
make pdf
102102
```
103103
104-
As of right now, the report PDF is in the `.gitignore` to prevent commit clogging, but will be in the final commit for submission. :)
104+
As of right now, the report PDF is in the `.gitignore` to prevent commit clogging, but will be in the final commit for submission. :)

deployment/chatbot.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,41 @@
44
from langchain_openai import ChatOpenAI
55
from typing import Tuple
66
import os
7+
import numpy
78

8-
# Rename .env.example to .env, can use bash command below
9-
# mv .env.example .env
10-
load_dotenv()
9+
10+
load_dotenv(os.path.join(os.getcwd(), "chatbot", "pyvenv.cfg"))
11+
api_key = os.getenv("OPENAI_API_KEY")
1112

1213
model = ChatOpenAI(model = "gpt-4o")
1314

1415
process_prompt = PromptTemplate(
15-
input_variables = ["text", "has_text", "emoji_img", "emoji_txt"],
16+
input_variables = ["text", "image", "has_text", "emoji_img", "emoji_txt"],
17+
1618
template = """
17-
You are an emoji-enhanced assistant that processes both images and text. Based on the inputs below, produce exactly one output:
19+
You are an expressive, emoji-savvy assistant that processes both images and text. Based on the inputs below, generate one clear, engaging response:
20+
21+
Instructions:
22+
- If **has_text** is false:
23+
→ Generate a fun and creative caption for the image ({image}).
24+
→ Use the provided emoji ({emoji_img}) as part of the caption.
1825
19-
- If has_text is false: generate an engaging image caption using the emoji from the image ({emoji_img}).
20-
- If has_text is true and emoji_img is empty: amplify the emotional tone of the text "{text}" using the emoji from text ({emoji_txt}).
21-
- If both emoji_img and emoji_txt are present: choose the best emoji between {emoji_img} and {emoji_txt}, then amplify "{text}" with that emoji.
26+
- If **has_text** is true and **emoji_img** is empty:
27+
→ Enhance the emotional tone of the text: "{text}".
28+
→ Use the emoji extracted from the text ({emoji_txt}) to enrich it.
2229
23-
Return only the final result and make sure to incorporate the emoji in the text. The emoji doesn't need to be at the end of the text.
30+
- If both **emoji_img** and **emoji_txt** are present:
31+
→ Try to guess the caption's emotion and amplify it: "{text}".
32+
→ Choose the more fitting emoji between {emoji_img} and {emoji_txt}.
33+
→ Incorporate it to the text that you have amplified!
34+
35+
Final Output:
36+
Return only the modified caption or text — naturally enhanced with the chosen emoji.
37+
You can use the emoji more than one time and put it in the middle of the sentences.
38+
Avoid being excessive on using the emojis as well though.
39+
Avoid explanations. The output should be concise, expressive, and emoji-infused.
2440
"""
41+
2542
)
2643
process_chain = LLMChain(llm = model, prompt = process_prompt)
2744

@@ -40,6 +57,7 @@ def process(text: str = "", image: Image.Image = None) -> Tuple[str, str]:
4057

4158
response = process_chain.invoke({
4259
"text": text,
60+
"image" : image,
4361
"has_text": str(has_text).lower(),
4462
"emoji_img": emoji_img,
4563
"emoji_txt": emoji_txt,

deployment/streamlit_app.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
import streamlit as st
33
from PIL import Image
44
from chatbot import process
5-
5+
import warnings
66
load_dotenv()
77

8+
warnings.filterwarnings("ignore", category=DeprecationWarning)
9+
10+
811
st.set_page_config(page_title = "Emoji-Enhanced Chatbot", layout = "centered")
912
st.title("Emoji-Enhanced Caption & Text Chatbot")
1013

@@ -16,13 +19,13 @@
1619
output, _ = process(user_text, image)
1720

1821
if image and not user_text:
19-
st.image(image, caption="Uploaded image", use_column_width=True)
22+
st.image(image, caption="Uploaded image", use_container_width=True)
2023
st.markdown(f"**Caption:** {output}")
2124
elif user_text and not image:
2225
st.markdown(f"**Amplified Text:** {output}")
2326
else:
2427
if image:
25-
st.image(image, caption="Uploaded image", use_column_width=True)
28+
st.image(image, caption="Uploaded image", use_container_width=True)
2629
st.markdown(f"**Output:** {output}")
2730
else:
2831
st.info("Please upload an image or enter text, then click Generate.")

0 commit comments

Comments
 (0)