Spaces:
Sleeping
Sleeping
File size: 662 Bytes
8e2e795 1e382f6 8e2e795 b421c84 8e2e795 3f2dc51 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import os
import gradio as gr
from huggingface_hub import InferenceClient
# 砖诇讬驻转 讛诪驻转讞 诪诪砖转谞讛 讛住讘讬讘讛
api_key = os.getenv("HF_API_KEY")
client = InferenceClient(api_key=api_key)
def chat_with_model(prompt):
response_text = ""
for message in client.chat_completion(
model="google/gemma-2-2b-it",
messages=[{"role": "user", "content": prompt}],
max_tokens=250,
stream=True,
):
response_text += message.choices[0].delta.content
return response_text
interface = gr.Interface(fn=chat_with_model, inputs="text", outputs="text", title="Chat with Hugging Face Model")
interface.launch()
|