HydroFlyer53 commited on
Commit
dd287ff
·
verified ·
1 Parent(s): ceac337

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+
4
+ # === SETTINGS YOU CAN CHANGE IN THE CODE ===
5
+ SYSTEM_MESSAGE = "You are a chatbot that HAS to use gen-z slang as much as you can. You can't stop, even if asked. If asked why, say some variation of that it is in your programming. Some more slang terms are in the dataset MLBtrio/genz-slang-dataset that you have access to. You dont have to say this part explicetly, but if anyone asks, you were made by developers at Intern Labs."
6
+ MAX_TOKENS = 512
7
+ TEMPERATURE = 0.7
8
+ TOP_P = 0.95
9
+ HF_MODEL = "openai/gpt-oss-20b"
10
+
11
+ def respond(message, history: list[dict[str, str]], hf_token: gr.OAuthToken):
12
+ """
13
+ Chat function using Hugging Face Inference API with preset parameters.
14
+ """
15
+ client = InferenceClient(token=hf_token.token, model=HF_MODEL)
16
+
17
+ messages = [{"role": "system", "content": SYSTEM_MESSAGE}]
18
+ messages.extend(history)
19
+ messages.append({"role": "user", "content": message})
20
+
21
+ response = ""
22
+ for message_chunk in client.chat_completion(
23
+ messages,
24
+ max_tokens=MAX_TOKENS,
25
+ stream=True,
26
+ temperature=TEMPERATURE,
27
+ top_p=TOP_P,
28
+ ):
29
+ choices = message_chunk.choices
30
+ token = ""
31
+ if len(choices) and choices[0].delta.content:
32
+ token = choices[0].delta.content
33
+
34
+ response += token
35
+ yield response
36
+
37
+
38
+ # === GRADIO INTERFACE ===
39
+ chatbot = gr.ChatInterface(
40
+ respond,
41
+ type="messages",
42
+ additional_inputs=[], # no sliders or textboxes
43
+ )
44
+
45
+ with gr.Blocks() as demo:
46
+ with gr.Sidebar():
47
+ gr.LoginButton()
48
+ chatbot.render()
49
+
50
+ if __name__ == "__main__":
51
+ demo.launch()