Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| from langchain.llms import HuggingFacePipeline | |
| from langchain.prompts import PromptTemplate | |
| from langchain.chains import LLMChain | |
| # Load model | |
| pipe = pipeline("text-generation", model="gpt2", max_length=100) | |
| llm = HuggingFacePipeline(pipeline=pipe) | |
| # Prompt template | |
| prompt = PromptTemplate.from_template("User: {question}\nBot:") | |
| chain = LLMChain(prompt=prompt, llm=llm) | |
| # Gradio chatbot function | |
| def chatbot_response(user_input): | |
| return chain.run(user_input).strip() | |
| # Gradio UI | |
| ui = gr.Interface( | |
| fn=chatbot_response, | |
| inputs="text", | |
| outputs="text", | |
| title="π€ My LangChain Chatbot", | |
| description="Ask me anything!", | |
| ) | |
| ui.launch() | |