Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +35 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Load instruction-following model
|
| 5 |
+
generator = pipeline("text2text-generation", model="google/flan-t5-xl", max_length=100)
|
| 6 |
+
|
| 7 |
+
# Few-shot prompt
|
| 8 |
+
FEW_SHOT_PROMPT = """You are a friendly chatbot. Respond like a helpful assistant.
|
| 9 |
+
|
| 10 |
+
User: Hello
|
| 11 |
+
Bot: Hi there! How can I assist you?
|
| 12 |
+
|
| 13 |
+
User: Tell me a joke.
|
| 14 |
+
Bot: Why don’t scientists trust atoms? Because they make up everything!
|
| 15 |
+
|
| 16 |
+
User: What's the weather like?
|
| 17 |
+
Bot: I'm not sure about your location, but I hope it's sunny!
|
| 18 |
+
|
| 19 |
+
User: {user_input}
|
| 20 |
+
Bot:"""
|
| 21 |
+
|
| 22 |
+
# Chatbot function
|
| 23 |
+
def chat_response(user_input):
|
| 24 |
+
prompt = FEW_SHOT_PROMPT.format(user_input=user_input)
|
| 25 |
+
response = generator(prompt)[0]['generated_text']
|
| 26 |
+
return response.strip()
|
| 27 |
+
|
| 28 |
+
# Gradio UI
|
| 29 |
+
gr.Interface(
|
| 30 |
+
fn=chat_response,
|
| 31 |
+
inputs="text",
|
| 32 |
+
outputs="text",
|
| 33 |
+
title="Few-Shot Chatbot",
|
| 34 |
+
description="A chatbot that uses few-shot prompting with FLAN-T5."
|
| 35 |
+
).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
gradio
|
| 3 |
+
torch
|