Spaces:
Runtime error
Runtime error
Commit ·
103a097
1
Parent(s): 2f1b4a1
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, FalconModel
|
| 3 |
+
|
| 4 |
+
tokenizer = AutoTokenizer.from_pretrained("Rocketknight1/falcon-rw-1b")
|
| 5 |
+
model = FalconModel.from_pretrained("Rocketknight1/falcon-rw-1b")
|
| 6 |
+
|
| 7 |
+
def chat(input_text):
|
| 8 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
| 9 |
+
outputs = model(**inputs)
|
| 10 |
+
last_hidden_states = outputs.last_hidden_state
|
| 11 |
+
response = tokenizer.decode(last_hidden_states.squeeze(), skip_special_tokens=True)
|
| 12 |
+
return response
|
| 13 |
+
|
| 14 |
+
interface = gr.Interface(
|
| 15 |
+
fn=chat,
|
| 16 |
+
inputs=gr.inputs.Textbox(lines=2, label="User Question"),
|
| 17 |
+
outputs=gr.outputs.Textbox(label="Chatbot Response"),
|
| 18 |
+
title="Falcon-7b",
|
| 19 |
+
theme="dark"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
interface.launch()
|