Update app.py
Browse files
app.py
CHANGED
|
@@ -40,8 +40,14 @@ Instagram Caption:
|
|
| 40 |
|
| 41 |
hf_api_key = os.environ["HF_API_KEY"]
|
| 42 |
|
| 43 |
-
def generate_caption(image_file_path, model_name):
|
| 44 |
image_to_text = ImageCaptioner(model_name="Salesforce/blip-image-captioning-base")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
prompt_builder = ChatPromptBuilder(template=prompt_template, required_variables="*")
|
| 46 |
generator = HuggingFaceAPIChatGenerator(
|
| 47 |
api_type="serverless_inference_api",
|
|
@@ -69,6 +75,11 @@ with gr.Blocks(theme="soft") as demo:
|
|
| 69 |
value="deepseek-ai/DeepSeek-V3.1-Terminus",
|
| 70 |
label="Choose your model!"
|
| 71 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
gr.Examples(["./whale.png", "./rainbow.jpeg", "./selfie.png"], inputs=image, label="Click on any example")
|
| 73 |
submit_btn = gr.Button("✨ Captionate ✨")
|
| 74 |
caption = gr.Textbox(label="Caption", show_copy_button=True)
|
|
|
|
| 40 |
|
| 41 |
hf_api_key = os.environ["HF_API_KEY"]
|
| 42 |
|
| 43 |
+
def generate_caption(image_file_path, model_name, user_prompt):
|
| 44 |
image_to_text = ImageCaptioner(model_name="Salesforce/blip-image-captioning-base")
|
| 45 |
+
# รวม prompt หลัก + user input
|
| 46 |
+
full_prompt_text = base_prompt
|
| 47 |
+
if user_prompt.strip():
|
| 48 |
+
full_prompt_text += f"\nMake it themed like: {user_prompt.strip()}"
|
| 49 |
+
|
| 50 |
+
prompt_template = [ChatMessage.from_user(full_prompt_text)]
|
| 51 |
prompt_builder = ChatPromptBuilder(template=prompt_template, required_variables="*")
|
| 52 |
generator = HuggingFaceAPIChatGenerator(
|
| 53 |
api_type="serverless_inference_api",
|
|
|
|
| 75 |
value="deepseek-ai/DeepSeek-V3.1-Terminus",
|
| 76 |
label="Choose your model!"
|
| 77 |
)
|
| 78 |
+
# 🆕 ช่องให้ผู้ใช้พิมพ์ธีมของ Caption
|
| 79 |
+
user_prompt = gr.Textbox(
|
| 80 |
+
label="Add a theme or tone (e.g. romantic, funny, luxury...)",
|
| 81 |
+
placeholder="Type here to customize the caption style"
|
| 82 |
+
|
| 83 |
gr.Examples(["./whale.png", "./rainbow.jpeg", "./selfie.png"], inputs=image, label="Click on any example")
|
| 84 |
submit_btn = gr.Button("✨ Captionate ✨")
|
| 85 |
caption = gr.Textbox(label="Caption", show_copy_button=True)
|