Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
def main():
|
| 5 |
+
st.title("Chatbot with Hugging Face Model")
|
| 6 |
+
|
| 7 |
+
model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
|
| 10 |
+
|
| 11 |
+
user_input = st.text_input("User Input:", "What is your favourite condiment?")
|
| 12 |
+
|
| 13 |
+
if st.button("Generate Response"):
|
| 14 |
+
messages = [
|
| 15 |
+
{"role": "user", "content": user_input},
|
| 16 |
+
{"role": "assistant", "content": "Placeholder assistant message"} # You can modify this as needed
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
|
| 20 |
+
|
| 21 |
+
outputs = model.generate(inputs, max_new_tokens=20)
|
| 22 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 23 |
+
|
| 24 |
+
st.text_area("Assistant's Response:", response)
|
| 25 |
+
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
main()
|