simplebot / app.py
Shankarm08's picture
Update app.py
3e35087 verified
Raw
History Blame Contribute Delete
815 Bytes
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()