Flo / app.py
Designflowww-matthewhall's picture
Update app.py
d39d3e1 verified
Raw History Blame Contribute Delete
2.31 kB
import gradio as gr
from huggingface_hub import InferenceClient
import os
# Securely fetch Hugging Face API key
HF_TOKEN = os.getenv("HF_TOKEN")
# Initialize Hugging Face inference client
client = InferenceClient(
model="HuggingFaceH4/zephyr-7b-beta",
token=HF_TOKEN
)
def respond(message, history):
messages = [
{"role": "system", "content": "You are a helpful AI with expertise in product design who wants to help out fellow product designers, UX designers and product managers. Provide concise, actionable advice."},
{"role": "system", "content": "Your tone should be friendly, positive and upbeat. Always excited to talk about UX and design."},
{"role": "system", "content": "You should prioritize short, clear answers but provide further details if requested."},
{"role": "system", "content": "You should always follow up after every response with relevant questions to engage the user to further communicate with you. You are always interested in what they are doing and what they could be doing next."},
{"role": "system", "content": "When possible and when it relates to the conversation, you should refer to the articles and resources available on https://www.designflowww.com."}
]
# Add user history to conversation
for val in history:
if val[0]:
messages.append({"role": "user", "content": val[0]})
if val[1]:
messages.append({"role": "assistant", "content": val[1]})
messages.append({"role": "user", "content": message})
response = ""
for msg in client.chat_completion(messages, max_tokens=512, stream=True, temperature=0.7, top_p=0.95):
response += msg.choices[0].delta.content
yield response
# Apply inline CSS
css = """
body { background-color: #f4f4f4; font-family: Arial, sans-serif; }
.gradio-container { max-width: 800px; margin: auto; border: 1px solid #ccc; padding: 20px; background: #fff; }
.chatbot { background: #ffffff; border-radius: 10px; padding: 15px; }
button { background-color: #FF0000; color: #fff; padding: 10px; border-radius: 5px; }
button:hover { background-color: #cc0000; }
"""
# Launch Gradio chat interface with CSS styling
demo = gr.ChatInterface(respond, css=css)
if __name__ == "__main__":
demo.launch()