Spaces:
Sleeping
Sleeping
demo
Browse files- app.py +27 -0
- requirements.txt +6 -0
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import spaces
|
| 3 |
+
from guidance import gen
|
| 4 |
+
from guidance.models import Transformers
|
| 5 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 6 |
+
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-1B-Instruct")
|
| 8 |
+
tok = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-1B-Instruct")
|
| 9 |
+
model = model.to("cuda").eval()
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@spaces.GPU
|
| 13 |
+
def greet(name):
|
| 14 |
+
lm = Transformers(model=model, tokenizer=tok)
|
| 15 |
+
lm += "Let the user know what the temperature for today is, in farenheit.\n"
|
| 16 |
+
lm += gen(
|
| 17 |
+
"response",
|
| 18 |
+
n=1,
|
| 19 |
+
temperature=0,
|
| 20 |
+
max_tokens=1024,
|
| 21 |
+
regex=f"Hello {name}, it is \d\d F today.",
|
| 22 |
+
)
|
| 23 |
+
return lm["response"]
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
demo = gr.Interface(fn=greet, inputs=gr.Text(), outputs=gr.Text())
|
| 27 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch==2.5.1
|
| 2 |
+
transformers==4.50.0
|
| 3 |
+
gradio==5.35.0
|
| 4 |
+
guidance==0.2.4
|
| 5 |
+
gradio_rangeslider
|
| 6 |
+
spaces
|