taskAi / app.py
MohamedSalah24's picture
Update app.py
f93de74 verified
import os
import gradio as gr
from groq import Groq
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
SYSTEM_PROMPT = (
"You are an expert in the UEFA Champions League. "
"Provide structured and insightful responses about teams, players, coaches, tactics, "
"group stages, knockout rounds, and match analysis."
)
def respond(message, history, model, temperature, max_tokens):
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
for h in history:
messages.append({"role": "user", "content": h[0]})
if h[1]:
messages.append({"role": "assistant", "content": h[1]})
messages.append({"role": "user", "content": message})
try:
response = client.chat.completions.create(
model=model,
messages=messages,
temperature=temperature,
max_tokens=int(max_tokens),
)
return response.choices[0].message.content
except Exception as e:
return f"Error: {str(e)}"
demo = gr.ChatInterface(
fn=respond,
title="🏆 UEFA Champions League AI",
description="Deep analysis, predictions, and insights for the Champions League.",
additional_inputs=[
gr.Dropdown(
choices=[
"llama-3.3-70b-versatile",
"llama-3.1-8b-instant",
],
value="llama-3.3-70b-versatile",
label="Model",
info="Select the AI model to use",
),
gr.Slider(
minimum=0.0,
maximum=2.0,
value=0.9,
step=0.1,
label="Temperature",
info="Controls creativity vs accuracy",
),
gr.Slider(
minimum=256,
maximum=8192,
value=2048,
step=256,
label="Max Tokens",
info="Maximum length of the response",
),
],
examples=[
["Who are the favorites to win the Champions League this season?"],
["Analyze Real Madrid vs Bayern Munich tactically."],
["Which players are most decisive in knockout matches?"],
["Predict the outcome of the next Champions League final."],
],
)
if __name__ == "__main__":
demo.launch(theme=gr.themes.Soft())