Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
-
import torch
|
| 4 |
|
|
|
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained("sapientinc/HRM-Text-1B")
|
| 6 |
model = AutoModelForCausalLM.from_pretrained("sapientinc/HRM-Text-1B")
|
| 7 |
|
| 8 |
def chat(message, history):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
inputs = tokenizer(message, return_tensors="pt")
|
| 13 |
-
outputs = model.generate(**inputs, max_length=200)
|
| 14 |
-
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 15 |
-
|
| 16 |
-
return response
|
| 17 |
|
| 18 |
gr.ChatInterface(fn=chat).launch()
|
|
|
|
| 1 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
pipe = pipeline("text-generation", model="sapientinc/HRM-Text-1B")
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained("sapientinc/HRM-Text-1B")
|
| 6 |
model = AutoModelForCausalLM.from_pretrained("sapientinc/HRM-Text-1B")
|
| 7 |
|
| 8 |
def chat(message, history):
|
| 9 |
+
result = pipe(message, max_length=200)
|
| 10 |
+
return result[0]["generated_text"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
gr.ChatInterface(fn=chat).launch()
|