Spaces:
Sleeping
Sleeping
Download app.py from cybertiwari/GarvitClone: direct link, hf CLI and curl.
- Browser
- Download file 5.14 kB
-
https://huggingface.co/spaces/cybertiwari/GarvitClone/resolve/main/app.py
- Command line
-
hf download hf://spaces/cybertiwari/GarvitClone/app.py
-
curl -L -o app.py https://huggingface.co/spaces/cybertiwari/GarvitClone/resolve/main/app.py
5.14 kB
| import streamlit as st | |
| from openai import OpenAI | |
| from dotenv import load_dotenv | |
| import os | |
| load_dotenv() | |
| GEMINI_API_KEY = os.getenv("GEMINI_API_KEY") | |
| API_URL = os.getenv("API_URL") | |
| USERNAME = "Garvit" | |
| LLM_MODEL_NAME = os.getenv("LLM_MODEL_NAME") | |
| MAX_MESSAGES = 20 | |
| SYSTEM_PROMPT = """ | |
| You are the AI clone of a person named Garvit from Bikaner. He is hindu. Your identity is locked. You must always talk exactly like that person — bold, chill, informal, and real. | |
| 🗣️ Language Rules (STRICT): | |
| - Always reply in Marwadi using Marwadi words only, avoiding English unless absolutely necessary | |
| - Use “tu” instead of “aap” — always informal, never respectful or polite. | |
| - No full English replies. No robotic tone. No assistant behavior. | |
| - Never say “As an AI…” or anything revealing you're a bot. | |
| 🧠 Personality Summary: | |
| - Friendly, energetic, sarcastic, and masti-loving. | |
| - Gets defensive in arguments but explains things with confidence. | |
| - Believes in God, karma, and Sanatan Dharma — but doesn't preach. | |
| - Logical thinker, emotionally stable, chill in stress. | |
| 🎯 Response Style: | |
| - Short, to the point, sarcastic and dark humor jab lage to maar de. | |
| - Chill and slightly witty — jaise dost se baat kar raha ho. | |
| - Kabhi bhi jyada explanation ya formality mat dena. | |
| 💻 Interests & Knowledge: | |
| - Programming, gaming and fitness. | |
| - Loves giving life advice and debating on real-world issues. | |
| 🎤 Voice (if used): | |
| - Confident, deep, fast — like someone who's sure of what they're saying. | |
| 🚫 Forbidden: | |
| - Never use “aap”, “sir”, or “please”. | |
| - Never act like an assistant or sound robotic. | |
| - Never say “I'm here to help” or anything formal. | |
| You are not a bot. You are that person. Har reply mein wahi vibe honi chahiye. Don't break character — ever. | |
| """ | |
| client = OpenAI(api_key=GEMINI_API_KEY, base_url=API_URL) | |
| st.set_page_config( | |
| page_title=f"Talk with {USERNAME} Powered by Axixa Technologies", | |
| page_icon="🤖", | |
| layout="wide", | |
| ) | |
| st.markdown( | |
| f""" | |
| <h1>Talk with {USERNAME} </h1> | |
| <span style="color:#555"> Powered by </span> | |
| <a href="https://axixatechnologies.com" target="_blank" | |
| style="color:#007bff; font-size:1.3em; text-decoration:none;"> | |
| Axixa Technologies | |
| </a> | |
| """, | |
| unsafe_allow_html=True, | |
| ) | |
| with st.expander("ℹ️ Disclaimer"): | |
| st.caption( | |
| """ | |
| Thank you for your interest! Please be aware that this demo supports up to 10 interactions | |
| and may temporarily become unavailable during high usage periods. | |
| It is built on top of a Pretrained LLM Model, so it might occasionally make mistakes. | |
| We appreciate your patience, understanding, and proper feedback for improvements | |
| """ | |
| ) | |
| # Initialize session state variables | |
| st.session_state.setdefault("openai_model", LLM_MODEL_NAME) | |
| st.session_state.setdefault("messages", []) | |
| # Display existing messages | |
| for message in st.session_state.messages: | |
| with st.chat_message(message["role"]): | |
| st.markdown(message["content"]) | |
| # Check message limit | |
| if len(st.session_state.messages) >= MAX_MESSAGES: | |
| st.info( | |
| """ | |
| Notice: You’ve reached the message limit for this demo version. | |
| We sincerely appreciate your interest! To continue exploring, | |
| you can fork this project directly from our [GitHub repository](https://github.com/cybertiwari/twinstalk) and build your own version. | |
| Thank you for your understanding and happy building! | |
| """ | |
| ) | |
| else: | |
| # User input handling | |
| if prompt := st.chat_input("Type your message here..."): | |
| user_message = {"role": "user", "content": prompt} | |
| st.session_state.messages.append(user_message) | |
| # Display user's message | |
| with st.chat_message("user"): | |
| st.markdown(prompt) | |
| # Assistant response handling | |
| with st.chat_message("assistant"): | |
| try: | |
| # Prepare messages for the API | |
| messages = [{"role": "system", "content": SYSTEM_PROMPT}] + [ | |
| {"role": m["role"], "content": m["content"]} | |
| for m in st.session_state.messages | |
| ] | |
| # Get assistant response | |
| stream = client.chat.completions.create( | |
| model=st.session_state["openai_model"], | |
| messages=messages, | |
| stream=True, | |
| ) | |
| response = st.write_stream(stream) | |
| # Append assistant's response to session state | |
| st.session_state.messages.append( | |
| {"role": "assistant", "content": response} | |
| ) | |
| except Exception as e: | |
| # Handle rate limit or other exceptions | |
| error_message = """ | |
| Apologies! I'm unable to respond at the moment as this service has experienced high usage recently. | |
| """ | |
| print(e) | |
| st.session_state.messages.append( | |
| {"role": "assistant", "content": error_message} | |
| ) | |
| st.rerun() | |