Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 3 |
+
|
| 4 |
+
# Load the model and tokenizer from Hugging Face
|
| 5 |
+
model_name = "google/flan-t5-large"
|
| 6 |
+
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
| 7 |
+
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
# Streamlit app title
|
| 10 |
+
st.title("AIBUDDY Chatbot")
|
| 11 |
+
|
| 12 |
+
# User input
|
| 13 |
+
input_text = st.text_area("Enter your query:", "Translate English to French: 'Hello, how are you?'")
|
| 14 |
+
|
| 15 |
+
if st.button("Generate"):
|
| 16 |
+
# Tokenize input
|
| 17 |
+
input_ids = tokenizer(input_text, return_tensors="pt").input_ids
|
| 18 |
+
|
| 19 |
+
# Generate output
|
| 20 |
+
with st.spinner("Generating response..."):
|
| 21 |
+
output = model.generate(input_ids, max_length=100, num_return_sequences=1)
|
| 22 |
+
|
| 23 |
+
# Decode the output
|
| 24 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 25 |
+
|
| 26 |
+
# Display the response
|
| 27 |
+
st.subheader("Response:")
|
| 28 |
+
st.write(response)
|
| 29 |
+
|
| 30 |
+
# Run the app using the command: streamlit run your_script_name.py
|