Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,8 +13,8 @@ import ast
|
|
| 13 |
logging.basicConfig(level=logging.INFO)
|
| 14 |
logger = logging.getLogger(__name__)
|
| 15 |
|
| 16 |
-
# β
Model name - using
|
| 17 |
-
model_name = "
|
| 18 |
|
| 19 |
def load_model():
|
| 20 |
logger.info(f"π Loading model: {model_name}")
|
|
@@ -118,19 +118,12 @@ def generate_response(prompt, max_new_tokens=512, temperature=0.4, top_p=0.9, re
|
|
| 118 |
try:
|
| 119 |
logger.info(f"π Prompt: {prompt[:80]}...")
|
| 120 |
|
| 121 |
-
#
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
# Apply chat template
|
| 128 |
-
inputs = tokenizer.apply_chat_template(
|
| 129 |
-
message,
|
| 130 |
-
return_tensors="pt",
|
| 131 |
-
add_generation_prompt=True,
|
| 132 |
-
return_dict=True,
|
| 133 |
-
).to(model.device)
|
| 134 |
|
| 135 |
with torch.no_grad():
|
| 136 |
outputs = model.generate(
|
|
@@ -149,7 +142,7 @@ def generate_response(prompt, max_new_tokens=512, temperature=0.4, top_p=0.9, re
|
|
| 149 |
)
|
| 150 |
|
| 151 |
# Decode the response
|
| 152 |
-
decoded = tokenizer.decode(outputs[0][inputs
|
| 153 |
|
| 154 |
# Check for function calls
|
| 155 |
function_calls = []
|
|
@@ -185,12 +178,12 @@ iface = gr.Interface(
|
|
| 185 |
gr.Slider(1.0, 1.5, value=1.1, step=0.05, label="Repetition Penalty")
|
| 186 |
],
|
| 187 |
outputs=gr.Textbox(label="AI Response", lines=10, show_copy_button=True),
|
| 188 |
-
title="π€
|
| 189 |
-
description="Ask questions in English or δΈζ β Powered by
|
| 190 |
theme=gr.themes.Soft()
|
| 191 |
)
|
| 192 |
|
| 193 |
# β
Run the app
|
| 194 |
if __name__ == "__main__":
|
| 195 |
-
logger.info("π Starting
|
| 196 |
iface.launch(server_name="0.0.0.0", server_port=7860, share=False)
|
|
|
|
| 13 |
logging.basicConfig(level=logging.INFO)
|
| 14 |
logger = logging.getLogger(__name__)
|
| 15 |
|
| 16 |
+
# β
Model name - using Microsoft Phi-4 multimodal model
|
| 17 |
+
model_name = "microsoft/Phi-4-multimodal-instruct"
|
| 18 |
|
| 19 |
def load_model():
|
| 20 |
logger.info(f"π Loading model: {model_name}")
|
|
|
|
| 118 |
try:
|
| 119 |
logger.info(f"π Prompt: {prompt[:80]}...")
|
| 120 |
|
| 121 |
+
# For Phi-4 multimodal, we'll use a simpler approach
|
| 122 |
+
# Format the prompt for Phi-4
|
| 123 |
+
formatted_prompt = f"<|user|>\n{prompt}<|end|>\n<|assistant|>\n"
|
| 124 |
+
|
| 125 |
+
# Tokenize
|
| 126 |
+
inputs = tokenizer(formatted_prompt, return_tensors="pt").to(model.device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
with torch.no_grad():
|
| 129 |
outputs = model.generate(
|
|
|
|
| 142 |
)
|
| 143 |
|
| 144 |
# Decode the response
|
| 145 |
+
decoded = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
| 146 |
|
| 147 |
# Check for function calls
|
| 148 |
function_calls = []
|
|
|
|
| 178 |
gr.Slider(1.0, 1.5, value=1.1, step=0.05, label="Repetition Penalty")
|
| 179 |
],
|
| 180 |
outputs=gr.Textbox(label="AI Response", lines=10, show_copy_button=True),
|
| 181 |
+
title="π€ Microsoft Phi-4 Multimodal AI Assistant",
|
| 182 |
+
description="Ask questions in English or δΈζ β Powered by microsoft/Phi-4-multimodal-instruct",
|
| 183 |
theme=gr.themes.Soft()
|
| 184 |
)
|
| 185 |
|
| 186 |
# β
Run the app
|
| 187 |
if __name__ == "__main__":
|
| 188 |
+
logger.info("π Starting Microsoft Phi-4 Multimodal Assistant...")
|
| 189 |
iface.launch(server_name="0.0.0.0", server_port=7860, share=False)
|