Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +26 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from langchain.llms import HuggingFaceHub
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Replace with your actual Hugging Face token
|
| 6 |
+
hf_token = os.getenv('HF_TOKEN2')
|
| 7 |
+
|
| 8 |
+
# Initialize the HuggingFace model
|
| 9 |
+
repo_id = "gpt2" # Make sure this is the correct repository ID
|
| 10 |
+
llm = HuggingFaceHub(repo_id=repo_id, huggingfacehub_api_token=hf_token, model_kwargs={"max_length": 128, "temperature": 0.7})
|
| 11 |
+
|
| 12 |
+
# Streamlit interface
|
| 13 |
+
st.title("Chat with GPT-2")
|
| 14 |
+
st.write("This chatbot is powered by a GPT-2 model hosted on Hugging Face.")
|
| 15 |
+
|
| 16 |
+
user_input = st.text_input("You:", "Type your message here...")
|
| 17 |
+
|
| 18 |
+
if st.button("Send"):
|
| 19 |
+
if user_input:
|
| 20 |
+
try:
|
| 21 |
+
response = llm(user_input)
|
| 22 |
+
st.write(f"Bot: {response}")
|
| 23 |
+
except Exception as e:
|
| 24 |
+
st.error(f"Error: {str(e)}")
|
| 25 |
+
else:
|
| 26 |
+
st.write("Please enter a message.")
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
langchain
|
| 3 |
+
huggingface_hub
|
| 4 |
+
langchain_community
|