Spaces:
Sleeping
Sleeping
Download app.py from delphine-cmd/GIMPA-Assistant: direct link, hf CLI and curl.
- Browser
- Download file 958 Bytes
-
https://huggingface.co/spaces/delphine-cmd/GIMPA-Assistant/resolve/main/app.py
- Command line
-
hf download hf://spaces/delphine-cmd/GIMPA-Assistant/app.py
-
curl -L -o app.py https://huggingface.co/spaces/delphine-cmd/GIMPA-Assistant/resolve/main/app.py
958 Bytes
| import gradio as gr | |
| from transformers import pipeline | |
| # Load model | |
| generator = pipeline("text-generation", model="microsoft/DialoGPT-medium") | |
| def chat(message, history): | |
| # Convert history (list of dicts) into a dialogue string | |
| conversation = "" | |
| if history: | |
| for msg in history: | |
| if msg["role"] == "user": | |
| conversation += f"User: {msg['content']}\n" | |
| else: | |
| conversation += f"Bot: {msg['content']}\n" | |
| conversation += f"User: {message}\nBot:" | |
| response = generator(conversation, max_new_tokens=150) | |
| reply = response[0]["generated_text"].split("Bot:")[-1].strip() | |
| history.append({"role": "user", "content": message}) | |
| history.append({"role": "assistant", "content": reply}) | |
| return "", history | |
| gr.ChatInterface( | |
| fn=chat, | |
| title="GIMPA Assistant 🤖", | |
| description="An AI Workmate powered by DialoGPT (offline and free).", | |
| theme="soft", | |
| ).launch() | |