Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import os | |
| from openai import OpenAI | |
| # Fata API Key ya OpenAI muri Hugging Face Secrets | |
| client = OpenAI(api_key=os.environ["OPENAI_API_KEY"]) | |
| ASSISTANT_NAME = "Viateur" | |
| def chat(user_message, history): | |
| prompt = f""" | |
| Witwa {ASSISTANT_NAME}, uri AI Assistant ikoresha Kinyarwanda. | |
| Subiza ibibazo byose mu Kinyarwanda neza kandi witonze. | |
| Ubutumwa bw'umukoresha: {user_message} | |
| """ | |
| # Kohereza request kuri OpenAI | |
| response = client.chat.completions.create( | |
| model="gpt-4o-mini", | |
| messages=[{"role": "user", "content": prompt}] | |
| ) | |
| answer = response.choices[0].message.content | |
| # Bika mu history y'iyi session gusa | |
| history = history + [(user_message, answer)] | |
| return history, history | |
| # Gradio Chat interface | |
| chat_interface = gr.ChatInterface( | |
| fn=chat, | |
| title=f"AI Assistant: {ASSISTANT_NAME}", | |
| description=f"Murakaza neza kuri {ASSISTANT_NAME}, AI Assistant yawe ikoresha Kinyarwanda." | |
| ) | |
| chat_interface.launch() |