Spaces:
Runtime error
Runtime error
Commit ·
aac4d82
1
Parent(s): 11c71be
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,38 @@
|
|
| 1 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 2 |
-
import torch
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
model_name,
|
| 10 |
-
torch_dtype=
|
| 11 |
-
device_map="auto"
|
| 12 |
)
|
| 13 |
|
|
|
|
| 14 |
def chat(input_text):
|
| 15 |
-
inputs = tokenizer(input_text, return_tensors="pt")
|
| 16 |
outputs = model.generate(**inputs, max_new_tokens=100, do_sample=True)
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
|
|
|
| 26 |
interface.launch()
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
|
| 4 |
+
# Load the model and tokenizer
|
| 5 |
+
model_name = "tiiuae/falcon-10b-instruct"
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
model = AutoModelForCausalLM.from_pretrained(
|
| 8 |
model_name,
|
| 9 |
+
torch_dtype="auto",
|
| 10 |
+
device_map="auto"
|
| 11 |
)
|
| 12 |
|
| 13 |
+
# Define a simple chat function
|
| 14 |
def chat(input_text):
|
| 15 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
| 16 |
outputs = model.generate(**inputs, max_new_tokens=100, do_sample=True)
|
| 17 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 18 |
+
return response
|
| 19 |
|
| 20 |
+
# Gradio interface
|
| 21 |
+
with gr.Blocks() as interface:
|
| 22 |
+
with gr.Row():
|
| 23 |
+
with gr.Column(scale=1):
|
| 24 |
+
# Add the avatar image
|
| 25 |
+
gr.Image("assets/rena2.rena2.png", elem_id="rena2-img").style(height=400, width=400)
|
| 26 |
+
with gr.Column(scale=3):
|
| 27 |
+
# Add the chat interface
|
| 28 |
+
gr.Textbox(
|
| 29 |
+
label="Your Message",
|
| 30 |
+
placeholder="Type something here...",
|
| 31 |
+
lines=4,
|
| 32 |
+
interactive=True,
|
| 33 |
+
).style(container=False)
|
| 34 |
+
gr.Button("Submit")
|
| 35 |
+
gr.Textbox(label="Falcon's Response", lines=4, interactive=False)
|
| 36 |
|
| 37 |
+
# Launch the app
|
| 38 |
interface.launch()
|