Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,20 @@
|
|
| 1 |
-
from huggingface_hub import InferenceClient
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
-
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
def
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
for user_input, model_output in history:
|
| 12 |
-
history_text += f"User: {user_input}\nAssistant: {model_output}\n"
|
| 13 |
-
full_prompt = history_text + f"User: {message}\nAssistant:"
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
)
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
return history
|
| 26 |
-
|
| 27 |
-
# Set up the Gradio app
|
| 28 |
-
gr.ChatInterface(
|
| 29 |
-
fn=chat_fn,
|
| 30 |
-
title="Community Chatbot",
|
| 31 |
-
description="A chatbot fine-tuned on community conversations using GPT-2.",
|
| 32 |
-
).launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load the text-generation pipeline
|
| 5 |
+
generator = pipeline("text-generation", model="King-8/community-gpt2")
|
| 6 |
|
| 7 |
+
# Define the chatbot response function
|
| 8 |
+
def chat(prompt):
|
| 9 |
+
response = generator(prompt, max_length=100, do_sample=True, temperature=0.7)
|
| 10 |
+
return response[0]["generated_text"]
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
# Set up the Gradio interface
|
| 13 |
+
iface = gr.Interface(fn=chat,
|
| 14 |
+
inputs="text",
|
| 15 |
+
outputs="text",
|
| 16 |
+
title="Community GPT-2 Chatbot",
|
| 17 |
+
description="Ask me anything!")
|
|
|
|
| 18 |
|
| 19 |
+
# Launch the app
|
| 20 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|