Nitzantry1 commited on
Commit
8e2e795
verified
1 Parent(s): 8b33880

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from huggingface_hub import InferenceClient
4
+
5
+ # 砖诇讬驻转 讛诪驻转讞 诪诪砖转谞讛 讛住讘讬讘讛
6
+ api_key = os.getenv("HF_API_KEY")
7
+ client = InferenceClient(api_key=api_key)
8
+
9
+ def chat_with_model(prompt):
10
+ response_text = ""
11
+ for message in client.chat_completion(
12
+ model="google/gemma-2-2b-it",
13
+ messages=[{"role": "user", "content": prompt}],
14
+ max_tokens=500,
15
+ stream=True,
16
+ ):
17
+ response_text += message.choices[0].delta.content
18
+ return response_text
19
+
20
+ interface = gr.Interface(fn=chat_with_model, inputs="text", outputs="text", title="Chat with Hugging Face Model")
21
+ interface.launch()