AI: Create/Update app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Gradio Chatbot with Gemma-3-1B-IT
|
| 2 |
+
|
| 3 |
+
from gradio import Interface, Chatbot
|
| 4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 5 |
+
|
| 6 |
+
# Load model and tokenizer
|
| 7 |
+
model_name = 'google/gemma-3-1b-it'
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 10 |
+
|
| 11 |
+
# Chatbot handler
|
| 12 |
+
def respond(message, chat_history):
|
| 13 |
+
inputs = tokenizer(message, return_tensors='pt')
|
| 14 |
+
outputs = model.generate(**inputs, max_new_tokens=100)
|
| 15 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 16 |
+
return response
|
| 17 |
+
|
| 18 |
+
# Create interface
|
| 19 |
+
chatbot = Chatbot()
|
| 20 |
+
iface = Interface(fn=respond, inputs=chatbot, outputs=chatbot)
|
| 21 |
+
|
| 22 |
+
# Launch app
|
| 23 |
+
if __name__ == '__main__':
|
| 24 |
+
iface.launch()
|