Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- requirements.txt +2 -2
- run.ipynb +1 -1
- run.py +1 -0
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
gradio-client @ git+https://github.com/gradio-app/gradio@
|
2 |
-
https://gradio-pypi-previews.s3.amazonaws.com/
|
3 |
transformers>=4.46.0
|
4 |
torch>=2.3.1
|
|
|
1 |
+
gradio-client @ git+https://github.com/gradio-app/gradio@d68c663fc9fffed4840fd74bed940fba3e2bc174#subdirectory=client/python
|
2 |
+
https://gradio-pypi-previews.s3.amazonaws.com/d68c663fc9fffed4840fd74bed940fba3e2bc174/gradio-5.42.0-py3-none-any.whl
|
3 |
transformers>=4.46.0
|
4 |
torch>=2.3.1
|
run.ipynb
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: llm_hf_transformers"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio transformers>=4.46.0 torch>=2.3.1 "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["from transformers import AutoModelForCausalLM, AutoTokenizer\n", "import gradio as gr\n", "\n", "checkpoint = \"HuggingFaceTB/SmolLM2-135M-Instruct\"\n", "device = \"cpu\" # \"cuda\" or \"cpu\"\n", "tokenizer = AutoTokenizer.from_pretrained(checkpoint)\n", "model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)\n", "\n", "def predict(message, history):\n", " history.append({\"role\": \"user\", \"content\": message})\n", " input_text = tokenizer.apply_chat_template(history, tokenize=False)\n", " inputs = tokenizer.encode(input_text, return_tensors=\"pt\").to(device) # type: ignore\n", " outputs = model.generate(inputs, max_new_tokens=100, temperature=0.2, top_p=0.9, do_sample=True)\n", " decoded = tokenizer.decode(outputs[0])\n", " response = decoded.split(\"<|im_start|>assistant\\n\")[-1].split(\"<|im_end|>\")[0]\n", " return response\n", "\n", "demo = gr.ChatInterface(predict, type=\"messages\")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: llm_hf_transformers"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio transformers>=4.46.0 torch>=2.3.1 "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# type: ignore\n", "from transformers import AutoModelForCausalLM, AutoTokenizer\n", "import gradio as gr\n", "\n", "checkpoint = \"HuggingFaceTB/SmolLM2-135M-Instruct\"\n", "device = \"cpu\" # \"cuda\" or \"cpu\"\n", "tokenizer = AutoTokenizer.from_pretrained(checkpoint)\n", "model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)\n", "\n", "def predict(message, history):\n", " history.append({\"role\": \"user\", \"content\": message})\n", " input_text = tokenizer.apply_chat_template(history, tokenize=False)\n", " inputs = tokenizer.encode(input_text, return_tensors=\"pt\").to(device) # type: ignore\n", " outputs = model.generate(inputs, max_new_tokens=100, temperature=0.2, top_p=0.9, do_sample=True)\n", " decoded = tokenizer.decode(outputs[0])\n", " response = decoded.split(\"<|im_start|>assistant\\n\")[-1].split(\"<|im_end|>\")[0]\n", " return response\n", "\n", "demo = gr.ChatInterface(predict, type=\"messages\")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
run.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
import gradio as gr
|
3 |
|
|
|
1 |
+
# type: ignore
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
import gradio as gr
|
4 |
|