Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
from typing import List, Tuple
|
4 |
+
|
5 |
+
|
6 |
+
model_name = "Hawoly18/Adia_Llama3.1"
|
7 |
+
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
10 |
+
|
11 |
+
def respond(
|
12 |
+
message: str,
|
13 |
+
history: List[Tuple[str, str]],
|
14 |
+
system_message: str,
|
15 |
+
max_tokens: int,
|
16 |
+
temperature: float,
|
17 |
+
top_p: float,
|
18 |
+
) -> str:
|
19 |
+
|
20 |
+
prompt = system_message
|
21 |
+
for user_msg, assistant_msg in history:
|
22 |
+
prompt += f"\nUser: {user_msg}\nAssistant: {assistant_msg}"
|
23 |
+
prompt += f"\nUser: {message}\nAssistant:"
|
24 |
+
|
25 |
+
|
26 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
27 |
+
outputs = model.generate(
|
28 |
+
**inputs,
|
29 |
+
max_length=max_tokens,
|
30 |
+
temperature=temperature,
|
31 |
+
top_p=top_p,
|
32 |
+
do_sample=True,
|
33 |
+
)
|
34 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True).split("Assistant:")[-1].strip()
|
35 |
+
return response
|
36 |
+
|
37 |
+
|
38 |
+
demo = gr.ChatInterface(
|
39 |
+
respond,
|
40 |
+
additional_inputs=[
|
41 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
42 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
43 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"), # Fixed syntax error
|
44 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
45 |
+
],
|
46 |
+
title="Chatbot Interface"
|
47 |
+
)
|
48 |
+
|
49 |
+
if __name__ == "__main__":
|
50 |
+
demo.launch()
|