Spaces:
Build error
Build error
Merge pull request #3 from jakewatson91/jake/testing_local
Browse filestrying to fix error with user_input.submit and added a local_model_test
app.py
CHANGED
|
@@ -5,7 +5,7 @@ from transformers import pipeline
|
|
| 5 |
|
| 6 |
# Inference client setup
|
| 7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
-
pipe = pipeline("text-generation", "microsoft/Phi-3-mini-4k-instruct", torch_dtype=torch.
|
| 9 |
|
| 10 |
# Global flag to handle cancellation
|
| 11 |
stop_inference = False
|
|
@@ -54,6 +54,7 @@ def respond(
|
|
| 54 |
messages,
|
| 55 |
max_new_tokens=max_tokens,
|
| 56 |
temperature=temperature,
|
|
|
|
| 57 |
do_sample=True,
|
| 58 |
top_p=top_p,
|
| 59 |
):
|
|
@@ -81,6 +82,7 @@ def respond(
|
|
| 81 |
max_tokens=max_tokens,
|
| 82 |
stream=True,
|
| 83 |
temperature=temperature,
|
|
|
|
| 84 |
top_p=top_p,
|
| 85 |
):
|
| 86 |
if stop_inference:
|
|
@@ -162,9 +164,16 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 162 |
cancel_button = gr.Button("Cancel Inference", variant="danger")
|
| 163 |
|
| 164 |
# Adjusted to ensure history is maintained and passed correctly
|
| 165 |
-
user_input.submit(respond, [user_input, chat_history,
|
| 166 |
|
| 167 |
cancel_button.click(cancel_inference)
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
if __name__ == "__main__":
|
|
|
|
| 170 |
demo.launch(share=False) # Remove share=True because it's not supported on HF Spaces
|
|
|
|
| 5 |
|
| 6 |
# Inference client setup
|
| 7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
+
pipe = pipeline("text-generation", "microsoft/Phi-3-mini-4k-instruct", torch_dtype=torch.float32, device_map="auto")
|
| 9 |
|
| 10 |
# Global flag to handle cancellation
|
| 11 |
stop_inference = False
|
|
|
|
| 54 |
messages,
|
| 55 |
max_new_tokens=max_tokens,
|
| 56 |
temperature=temperature,
|
| 57 |
+
practicality=practicality,
|
| 58 |
do_sample=True,
|
| 59 |
top_p=top_p,
|
| 60 |
):
|
|
|
|
| 82 |
max_tokens=max_tokens,
|
| 83 |
stream=True,
|
| 84 |
temperature=temperature,
|
| 85 |
+
practicality=practicality,
|
| 86 |
top_p=top_p,
|
| 87 |
):
|
| 88 |
if stop_inference:
|
|
|
|
| 164 |
cancel_button = gr.Button("Cancel Inference", variant="danger")
|
| 165 |
|
| 166 |
# Adjusted to ensure history is maintained and passed correctly
|
| 167 |
+
user_input.submit(respond, [user_input, chat_history, max_tokens, temperature, top_p, practicality, use_local_model], chat_history)
|
| 168 |
|
| 169 |
cancel_button.click(cancel_inference)
|
| 170 |
|
| 171 |
+
# Test the local model
|
| 172 |
+
def test_local_model():
|
| 173 |
+
prompt = "What is the meaning of life?"
|
| 174 |
+
response = pipe(prompt, max_new_tokens=50)
|
| 175 |
+
print(response)
|
| 176 |
+
|
| 177 |
if __name__ == "__main__":
|
| 178 |
+
test_local_model()
|
| 179 |
demo.launch(share=False) # Remove share=True because it's not supported on HF Spaces
|