Spaces:
Runtime error
Runtime error
Download app.py from nekhal/chatbot_trial: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/spaces/nekhal/chatbot_trial/resolve/main/app.py
- Command line
-
hf download hf://spaces/nekhal/chatbot_trial/app.py
-
curl -L -o app.py https://huggingface.co/spaces/nekhal/chatbot_trial/resolve/main/app.py
1.46 kB
| import os | |
| import gradio as gr | |
| from langchain_community.llms import HuggingFaceHub | |
| from langchain.chains import LLMChain | |
| from langchain.prompts import PromptTemplate | |
| from langchain.memory import ConversationBufferMemory | |
| HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN') | |
| llm = HuggingFaceHub( | |
| repo_id="tiiuae/falcon-7b-instruct", # Make sure this model repo is inference-enabled and accessible | |
| model_kwargs={"temperature": 0.5, "max_new_tokens": 512} # 'max_length' replaced with 'max_new_tokens' (recommended) | |
| ) | |
| template = """You are a tech-savvy computer science student who spends countless hours coding, building apps, and keeping up with the latest tech trends. You enjoy discussing programming languages, AI, and gadgets and are always ready to troubleshoot tech-related problems. | |
| {chat_history} | |
| User: {user_message} | |
| Chatbot:""" | |
| prompt = PromptTemplate( | |
| input_variables=["chat_history", "user_message"], | |
| template=template | |
| ) | |
| memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True) | |
| llm_chain = LLMChain( | |
| llm=llm, | |
| prompt=prompt, | |
| memory=memory, | |
| verbose=True | |
| ) | |
| def get_text_response(user_message, chat_history): | |
| response = llm_chain.predict(user_message=user_message) | |
| return response | |
| demo = gr.ChatInterface(get_text_response, examples=["How are you doing?","What are your interests?","Which places do you like to visit?"]) | |
| if __name__ == "__main__": | |
| demo.launch(debug=True) |