Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,21 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import pipeline, set_seed
|
3 |
|
|
|
4 |
generator = pipeline("text-generation", model="sshleifer/tiny-gpt2")
|
5 |
-
set_seed(42)
|
6 |
|
7 |
-
def chat_fn(message):
|
8 |
-
|
9 |
-
|
|
|
10 |
return reply
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
btn = gr.Button("Send")
|
21 |
-
btn.click(fn=chat_fn, inputs=user_input, outputs=output)
|
22 |
|
23 |
-
demo.launch()
|
|
|
1 |
+
from transformers import pipeline
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
+
# Load GPT-2 (or use sshleifer/tiny-gpt2 for low RAM)
|
5 |
generator = pipeline("text-generation", model="sshleifer/tiny-gpt2")
|
|
|
6 |
|
7 |
+
def chat_fn(message, history=[]):
|
8 |
+
prompt = message.strip()
|
9 |
+
result = generator(prompt, max_length=60, num_return_sequences=1)
|
10 |
+
reply = result[0]['generated_text'].replace(prompt, "").strip()
|
11 |
return reply
|
12 |
|
13 |
+
demo = gr.ChatInterface(
|
14 |
+
fn=chat_fn,
|
15 |
+
title="💬 GPT-2 Chatbot",
|
16 |
+
description="Powered by sshleifer/tiny-gpt2 for light, fast, local inference"
|
17 |
+
)
|
18 |
+
|
19 |
+
if __name__ == "__main__":
|
20 |
+
demo.launch(share=True)
|
|
|
|
|
21 |
|
|