abdullah378 commited on
Commit
f15e447
·
verified ·
1 Parent(s): f226d25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -8
app.py CHANGED
@@ -1,10 +1,32 @@
 
1
  import gradio as gr
 
2
 
3
- with gr.Blocks(fill_height=True) as demo:
4
- with gr.Sidebar():
5
- gr.Markdown("# Inference Provider")
6
- gr.Markdown("This Space showcases the google/gemma-2-9b-it model, served by the featherless-ai API. Sign in with your Hugging Face account to use this API.")
7
- button = gr.LoginButton("Sign in")
8
- gr.load("models/google/gemma-2-9b-it", accept_token=button, provider="featherless-ai")
9
-
10
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
  import gradio as gr
3
+ from huggingface_hub import InferenceClient
4
 
5
+ MODEL_NAME = "google/gemma-2-9b-it"
6
+ HF_TOKEN = os.getenv("HF_TOKEN")
7
+
8
+ client = InferenceClient(
9
+ model=MODEL_NAME,
10
+ token=HF_TOKEN
11
+ )
12
+
13
+ def chat(message, history):
14
+ messages = [{"role": "system", "content": "أنت مساعد ذكي."}]
15
+
16
+ for u, a in history:
17
+ if u:
18
+ messages.append({"role": "user", "content": u})
19
+ if a:
20
+ messages.append({"role": "assistant", "content": a})
21
+
22
+ messages.append({"role": "user", "content": message})
23
+
24
+ response = client.chat_completion(
25
+ messages=messages,
26
+ max_tokens=300
27
+ )
28
+
29
+ return response.choices[0].message["content"]
30
+
31
+ demo = gr.ChatInterface(chat)
32
+ demo.launch()