Spaces:
Sleeping
Sleeping
Download app.py from ONEROCKS/One_v.1.3.pool: direct link, hf CLI and curl.
- Browser
- Download file 2.61 kB
-
https://huggingface.co/spaces/ONEROCKS/One_v.1.3.pool/resolve/main/app.py
- Command line
-
hf download hf://spaces/ONEROCKS/One_v.1.3.pool/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ONEROCKS/One_v.1.3.pool/resolve/main/app.py
2.61 kB
| import streamlit as st | |
| import requests | |
| import os | |
| import datetime | |
| import speech_recognition as sr | |
| import pyttsx3 | |
| import tempfile | |
| # ---- CONFIG ---- | |
| st.set_page_config(page_title="Bunny.io Free", layout="wide") | |
| st.title("Bunny.io - Free AI with Sass") | |
| st.markdown("**Roasty, Shit-Talking, Deadpool Vibes AI Chatbot**") | |
| # ---- INIT ---- | |
| if "chat_history" not in st.session_state: | |
| st.session_state.chat_history = [] | |
| # ---- FUNNY VOICE OUTPUT ---- | |
| def speak(text): | |
| engine = pyttsx3.init() | |
| engine.say(text) | |
| engine.runAndWait() | |
| # ---- MOCK SERPER ---- | |
| def fake_search(query): | |
| return f"Live search isn't available in free version. You asked: '{query}'. Here's a sassy fake answer." | |
| # ---- OPENROUTER STUB ---- | |
| def openrouter_call(prompt): | |
| headers = { | |
| "Authorization": f"Bearer {os.getenv('OPENROUTER_API_KEY', 'demo-key')}", | |
| "Content-Type": "application/json" | |
| } | |
| payload = { | |
| "model": "mistralai/mistral-7b-instruct", | |
| "messages": [{"role": "user", "content": prompt}] | |
| } | |
| try: | |
| res = requests.post("https://openrouter.ai/api/v1/chat/completions", json=payload, headers=headers) | |
| return res.json()["choices"][0]["message"]["content"] | |
| except: | |
| return "Yo, the free brain is lagging or broken." | |
| # ---- FILE UPLOAD ---- | |
| uploaded_file = st.file_uploader("Upload a file", type=["txt", "pdf"]) | |
| if uploaded_file: | |
| st.write("Uploaded:", uploaded_file.name) | |
| file_text = uploaded_file.read().decode("utf-8", errors="ignore") | |
| st.text_area("File Contents", file_text[:1000]) | |
| # ---- VOICE INPUT ---- | |
| if st.button("Speak Now (Mic)"): | |
| recognizer = sr.Recognizer() | |
| with sr.Microphone() as source: | |
| st.write("Listening...") | |
| audio = recognizer.listen(source, phrase_time_limit=5) | |
| try: | |
| query = recognizer.recognize_google(audio) | |
| st.success(f"You said: {query}") | |
| except: | |
| st.error("Sorry, couldn't hear you clearly.") | |
| query = "" | |
| else: | |
| query = st.text_input("Type your message") | |
| # ---- HANDLE INPUT ---- | |
| if query: | |
| st.session_state.chat_history.append(("You", query)) | |
| if "search" in query.lower(): | |
| response = fake_search(query) | |
| else: | |
| prompt = f"You are Bunny.io, a sarcastic AI with a shit-talking Deadpool personality. Reply to: {query}" | |
| response = openrouter_call(prompt) | |
| speak(response) | |
| st.session_state.chat_history.append(("Bunny.io", response)) | |
| # ---- CHAT DISPLAY ---- | |
| st.markdown("### Chat History") | |
| for speaker, msg in reversed(st.session_state.chat_history): | |
| st.markdown(f"**{speaker}:** {msg}") | |