Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,42 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
"""
|
| 5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
"""
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
+
##############################################################
|
| 4 |
+
import torch
|
| 5 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 6 |
|
| 7 |
+
torch.random.manual_seed(0)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
+
"microsoft/Phi-3-mini-128k-instruct",
|
| 10 |
+
device_map="cuda",
|
| 11 |
+
torch_dtype="auto",
|
| 12 |
+
trust_remote_code=True,
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-128k-instruct")
|
| 16 |
+
|
| 17 |
+
messages = [
|
| 18 |
+
{"role": "system", "content": "You are a helpful AI assistant."},
|
| 19 |
+
{"role": "user", "content": "Can you provide ways to eat combinations of bananas and dragonfruits?"},
|
| 20 |
+
{"role": "assistant", "content": "Sure! Here are some ways to eat bananas and dragonfruits together: 1. Banana and dragonfruit smoothie: Blend bananas and dragonfruits together with some milk and honey. 2. Banana and dragonfruit salad: Mix sliced bananas and dragonfruits together with some lemon juice and honey."},
|
| 21 |
+
{"role": "user", "content": "What about solving an 2x + 3 = 7 equation?"},
|
| 22 |
+
]
|
| 23 |
+
|
| 24 |
+
pipe = pipeline(
|
| 25 |
+
"text-generation",
|
| 26 |
+
model=model,
|
| 27 |
+
tokenizer=tokenizer,
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
generation_args = {
|
| 31 |
+
"max_new_tokens": 500,
|
| 32 |
+
"return_full_text": False,
|
| 33 |
+
"temperature": 0.0,
|
| 34 |
+
"do_sample": False,
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
output = pipe(messages, **generation_args)
|
| 38 |
+
print(output[0]['generated_text'])
|
| 39 |
+
##############################################################
|
| 40 |
"""
|
| 41 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 42 |
"""
|