Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
| 3 |
|
| 4 |
-
|
| 5 |
-
st.title("ChatGPT Clone")
|
| 6 |
|
| 7 |
-
|
| 8 |
-
model_name = 'gpt2'
|
| 9 |
-
model = GPT2LMHeadModel.from_pretrained(model_name)
|
| 10 |
-
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
# Encode input text and generate response
|
| 16 |
-
if input_text:
|
| 17 |
-
# Encode the input text
|
| 18 |
-
input_ids = tokenizer.encode(input_text, return_tensors='pt')
|
| 19 |
-
# Generate a response
|
| 20 |
-
outputs = model.generate(input_ids, max_length=150, num_return_sequences=1, pad_token_id=tokenizer.eos_token_id)
|
| 21 |
-
# Decode the response
|
| 22 |
-
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 23 |
-
st.write("ChatGPT: ", response)
|
| 24 |
-
|
| 25 |
-
# Run the Streamlit application
|
| 26 |
-
if __name__ == '__main__':
|
| 27 |
-
st.sidebar.title("About")
|
| 28 |
-
st.sidebar.info("This is a simple ChatGPT clone using Hugging Face's Transformers library and Streamlit.")
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
+
st.title("Chat UI")
|
|
|
|
| 4 |
|
| 5 |
+
user_input = st.text_input("You: ")
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
if st.button("Send"):
|
| 8 |
+
st.write("You: ", user_input)
|
| 9 |
+
st.write("Bot: Hello, How can I help you?")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|