Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,18 @@
|
|
| 1 |
-
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 2 |
-
import time
|
| 3 |
import gradio as gr
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
outputs = model.generate(**inputs)
|
| 22 |
-
code=tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
| 23 |
-
for i in range(len(code)):
|
| 24 |
-
time.sleep(0.3)
|
| 25 |
-
yield code[: i+1]
|
| 26 |
-
|
| 27 |
-
gr.ChatInterface(reply).queue().launch()
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
# Load pretrained model and tokenizer
|
| 4 |
+
tokenizer = AutoTokenizer.from_pretrained("flan-t5-large")
|
| 5 |
+
model = AutoModelForCausalLM.from_pretrained("flan-t5-large")
|
| 6 |
+
|
| 7 |
+
def chatbot_model(prompt):
|
| 8 |
+
|
| 9 |
+
# Encode the prompt and generate response
|
| 10 |
+
input_ids = tokenizer.encode(prompt + tokenizer.eos_token, return_tensors='pt')
|
| 11 |
+
output = model.generate(input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id)
|
| 12 |
+
|
| 13 |
+
# Decode the output
|
| 14 |
+
decoded_output = tokenizer.decode(output[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
|
| 15 |
+
return decoded_output
|
| 16 |
+
|
| 17 |
+
iface = gr.Interface(fn=chatbot_model, inputs="text", outputs="text")
|
| 18 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|