Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from langchain.llms import HuggingFacePipeline
|
| 4 |
+
from langchain.prompts import PromptTemplate
|
| 5 |
+
from langchain.chains import LLMChain
|
| 6 |
+
|
| 7 |
+
# Load model
|
| 8 |
+
pipe = pipeline("text-generation", model="gpt2", max_length=100)
|
| 9 |
+
llm = HuggingFacePipeline(pipeline=pipe)
|
| 10 |
+
|
| 11 |
+
# Prompt template
|
| 12 |
+
prompt = PromptTemplate.from_template("User: {question}\nBot:")
|
| 13 |
+
chain = LLMChain(prompt=prompt, llm=llm)
|
| 14 |
+
|
| 15 |
+
# Gradio chatbot function
|
| 16 |
+
def chatbot_response(user_input):
|
| 17 |
+
return chain.run(user_input).strip()
|
| 18 |
+
|
| 19 |
+
# Gradio UI
|
| 20 |
+
ui = gr.Interface(
|
| 21 |
+
fn=chatbot_response,
|
| 22 |
+
inputs="text",
|
| 23 |
+
outputs="text",
|
| 24 |
+
title="🤖 My LangChain Chatbot",
|
| 25 |
+
description="Ask me anything!",
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
ui.launch()
|