Spaces:
Sleeping
Sleeping
Commit
·
621fcdc
1
Parent(s):
ceca154
New app
Browse files- README.md +12 -0
- app.py +44 -0
- requirements.txt +11 -0
README.md
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Test Chatbot
|
3 |
+
emoji: 💬
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: purple
|
6 |
+
sdk: gradio
|
7 |
+
app_file: app.py
|
8 |
+
pinned: false
|
9 |
+
license: mit
|
10 |
+
---
|
11 |
+
|
12 |
+
An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
|
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
3 |
+
|
4 |
+
# Load the model and tokenizer using Hugging Face
|
5 |
+
#model_name = "microsoft/Phi-3-mini-4k-instruct"
|
6 |
+
|
7 |
+
|
8 |
+
# Explicitly load the tokenizer and model
|
9 |
+
#tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
10 |
+
#model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
|
11 |
+
|
12 |
+
# Create the pipeline
|
13 |
+
chatbot = pipeline("text-generation", model="KingNish/Qwen2.5-0.5b-Test-ft", trust_remote_code=True)
|
14 |
+
#chatbot = pipeline("text-generation", model=model, tokenizer=tokenizer, framework="pt")
|
15 |
+
|
16 |
+
def respond(
|
17 |
+
message,
|
18 |
+
history: list[tuple[str, str]],
|
19 |
+
system_message,
|
20 |
+
max_tokens,
|
21 |
+
temperature,
|
22 |
+
top_p,
|
23 |
+
):
|
24 |
+
# Combine system message and conversation history
|
25 |
+
prompt = system_message + "\n"
|
26 |
+
prompt += f"User: {message}\n\nBot:"
|
27 |
+
|
28 |
+
# Generate the response using the model
|
29 |
+
response = chatbot(prompt, max_length=max_tokens, temperature=temperature, top_p=top_p)[0]['generated_text']
|
30 |
+
return response
|
31 |
+
|
32 |
+
# Define the Gradio interface with additional inputs
|
33 |
+
demo = gr.ChatInterface(
|
34 |
+
respond,
|
35 |
+
additional_inputs=[
|
36 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
37 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
38 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
39 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
40 |
+
],
|
41 |
+
)
|
42 |
+
|
43 |
+
if __name__ == "__main__":
|
44 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pip
|
2 |
+
setuptools
|
3 |
+
wheel
|
4 |
+
huggingface_hub==0.22.2
|
5 |
+
gradio
|
6 |
+
transformers
|
7 |
+
# tensorflow==2.15
|
8 |
+
# keras==2.15
|
9 |
+
torch==2.3.1
|
10 |
+
flask
|
11 |
+
datasets
|