Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,9 @@ from huggingface_hub import InferenceClient
|
|
| 17 |
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 18 |
MODEL_NAME = "microsoft/Phi-3-mini-4k-instruct"
|
| 19 |
|
|
|
|
|
|
|
|
|
|
| 20 |
# Load model and tokenizer, with specific handling for the Phi-3 model
|
| 21 |
try:
|
| 22 |
config = AutoConfig.from_pretrained(MODEL_NAME)
|
|
@@ -132,6 +135,12 @@ def model_inference(
|
|
| 132 |
repetition_penalty,
|
| 133 |
top_p,
|
| 134 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
if not user_prompt["files"]:
|
| 136 |
if web_search:
|
| 137 |
web_results = search(user_prompt["text"])
|
|
@@ -229,8 +238,10 @@ chatbot = gr.Chatbot(
|
|
| 229 |
|
| 230 |
# Define Gradio interface
|
| 231 |
def chat_interface(user_input, history, web_search, decoding_strategy, temperature, max_new_tokens, repetition_penalty, top_p):
|
|
|
|
|
|
|
| 232 |
response = model_inference(
|
| 233 |
-
|
| 234 |
history,
|
| 235 |
web_search,
|
| 236 |
decoding_strategy,
|
|
@@ -264,4 +275,4 @@ interface = gr.Interface(
|
|
| 264 |
)
|
| 265 |
|
| 266 |
if __name__ == "__main__":
|
| 267 |
-
interface.launch()
|
|
|
|
| 17 |
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 18 |
MODEL_NAME = "microsoft/Phi-3-mini-4k-instruct"
|
| 19 |
|
| 20 |
+
# Update transformers library
|
| 21 |
+
!pip install --upgrade transformers
|
| 22 |
+
|
| 23 |
# Load model and tokenizer, with specific handling for the Phi-3 model
|
| 24 |
try:
|
| 25 |
config = AutoConfig.from_pretrained(MODEL_NAME)
|
|
|
|
| 135 |
repetition_penalty,
|
| 136 |
top_p,
|
| 137 |
):
|
| 138 |
+
if not isinstance(user_prompt, dict):
|
| 139 |
+
return "Invalid input format. Expected a dictionary."
|
| 140 |
+
|
| 141 |
+
if "files" not in user_prompt:
|
| 142 |
+
user_prompt["files"] = []
|
| 143 |
+
|
| 144 |
if not user_prompt["files"]:
|
| 145 |
if web_search:
|
| 146 |
web_results = search(user_prompt["text"])
|
|
|
|
| 238 |
|
| 239 |
# Define Gradio interface
|
| 240 |
def chat_interface(user_input, history, web_search, decoding_strategy, temperature, max_new_tokens, repetition_penalty, top_p):
|
| 241 |
+
# Ensure user_input is a dictionary
|
| 242 |
+
user_input_dict = {"text": user_input, "files": []}
|
| 243 |
response = model_inference(
|
| 244 |
+
user_input_dict,
|
| 245 |
history,
|
| 246 |
web_search,
|
| 247 |
decoding_strategy,
|
|
|
|
| 275 |
)
|
| 276 |
|
| 277 |
if __name__ == "__main__":
|
| 278 |
+
interface.launch()
|