swift-ai-22 / app.py
AiCoderv2's picture
Deploy Gradio app with multiple files
819ac9a verified
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()