Spaces:
Sleeping
Sleeping
File size: 1,177 Bytes
819ac9a | 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 models import load_model, generate_response
from utils import format_history
from config import MODEL_NAME, MAX_LENGTH, TEMPERATURE
def chat_response(message, history):
# Format history for the model
formatted_history = format_history(history)
# Generate response using the model
response = generate_response(message, formatted_history, max_length=MAX_LENGTH, temperature=TEMPERATURE)
return response
with gr.Blocks() as demo:
gr.HTML("""
<div style="text-align: center; padding: 10px;">
<h1>AI Chatbot for Chat and Code</h1>
<p>Powered by <a href="https://huggingface.co/microsoft/Phi-2">microsoft/Phi-2</a></p>
<p><a href="https://huggingface.co/spaces/akhaliq/anycoder">Built with anycoder</a></p>
</div>
""")
chatbot = gr.ChatInterface(
fn=chat_response,
title="Chat and Code Assistant",
description="Ask me anything about coding, chat, or general questions!",
examples=["Write a Python function to reverse a string", "Explain recursion", "Hello, how are you?"],
theme=gr.themes.Soft()
)
if __name__ == "__main__":
demo.launch() |