| | import gradio as gr |
| | import requests |
| | import os |
| |
|
| | |
| | |
| | FLOWISE_API = os.getenv("FLOWISE_API", "https://kimberlee-homonymous-zora.ngrok-free.dev/api/v1/prediction/c7fbe69c-9c1e-45f8-8e94-c2c619886cae") |
| |
|
| | def chat_with_bot(message, history): |
| | """ |
| | Gửi câu hỏi người dùng đến Flowise API và nhận câu trả lời. |
| | """ |
| | payload = {"question": message} |
| | try: |
| | response = requests.post(FLOWISE_API, json=payload, timeout=60) |
| | data = response.json() |
| |
|
| | answer = data.get("text", "Keine Antwort gefunden.") |
| | sources = data.get("sourceDocuments", []) |
| |
|
| | if sources: |
| | refs = "\n\n**Quellen:**\n" + "\n".join([ |
| | f"- {src.get('metadata', {}).get('source', 'Unbekannt')}" |
| | for src in sources |
| | ]) |
| | else: |
| | refs = "" |
| |
|
| | return answer + refs |
| |
|
| | except Exception as e: |
| | return f"Fehler: {e}" |
| |
|
| | with gr.Blocks(theme=gr.themes.Soft()) as demo: |
| | gr.Markdown("# 🤖 Chatbot für Prüfungsrecht") |
| | gr.Markdown("Fragen Sie zur Prüfungsordnung oder zum Hochschulgesetz NRW. " |
| | "Der Chatbot zitiert direkt aus den Quellen (PDF & Webseite).") |
| |
|
| | chat = gr.ChatInterface( |
| | fn=chat_with_bot, |
| | title="Prüfungsrecht RAG-Chatbot", |
| | examples=[ |
| | "Was steht in §10 über Wiederholungsprüfungen?", |
| | "Welche Regel gilt laut Hochschulgesetz für Prüfungsanspruch?", |
| | ] |
| | ) |
| |
|
| | gr.HTML(""" |
| | <h3>📄 Quellen anzeigen</h3> |
| | <iframe src="https://recht.nrw.de/lmi/owa/br_text_anzeigen?v_id=10000000000000000654" width="100%" height="400"></iframe> |
| | """) |
| |
|
| | if __name__ == "__main__": |
| | demo.launch() |
| |
|