Spaces:
Runtime error
Runtime error
File size: 815 Bytes
b0c3193 3e35087 0817137 b0c3193 3e35087 0817137 3e35087 b0c3193 0817137 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import gradio as gr
from huggingface_hub import InferenceClient
# Public inference (no token required for many free models)
client = InferenceClient()
def chatbot(message, history):
messages = []
for user, assistant in history:
messages.append({"role": "user", "content": user})
messages.append({"role": "assistant", "content": assistant})
messages.append({"role": "user", "content": message})
try:
response = client.chat.completions.create(
model="microsoft/Phi-3-mini-4k-instruct",
messages=messages,
max_tokens=100,
)
return response.choices[0].message.content
except Exception as e:
return f"Error: {e}"
demo = gr.ChatInterface(
fn=chatbot,
title="Simple Hugging Face Chatbot"
)
demo.launch() |