Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
from transformers import
|
4 |
-
from diffusers import StableDiffusionPipeline
|
5 |
-
from huggingface_hub import login
|
6 |
-
import os
|
7 |
-
from PIL import Image
|
8 |
-
import io
|
9 |
|
10 |
-
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
model_id = "HuggingFaceH4/zephyr-7b-beta"
|
6 |
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
9 |
+
model_id,
|
10 |
+
torch_dtype=torch.bfloat16,
|
11 |
+
device_map="auto"
|
12 |
+
)
|
13 |
|
14 |
+
pipe = pipeline(
|
15 |
+
"text-generation",
|
16 |
+
model=model,
|
17 |
+
tokenizer=tokenizer,
|
18 |
+
max_new_tokens=200,
|
19 |
+
do_sample=True,
|
20 |
+
temperature=0.7,
|
21 |
+
top_p=0.9,
|
22 |
+
)
|
23 |
|
24 |
+
def responder(prompt):
|
25 |
+
respuesta = pipe(prompt)[0]["generated_text"]
|
26 |
+
return respuesta.split(prompt)[-1].strip()
|
27 |
+
|
28 |
+
gr.Interface(fn=responder, inputs="text", outputs="text", title="Bot de Texto").launch()
|