Text Generation
Transformers
Safetensors
English
phi3
phi
nlp
math
code
chat
conversational
reasoning
text-generation-inference
Run this model with HF Jobs
Run Ashok75/base2 on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/Ashok75/base2. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/Ashok75/base2 on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/Ashok75/base2. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/Ashok75/base2. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use Ashok75/base2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Ashok75/base2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Ashok75/base2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Ashok75/base2") model = AutoModelForCausalLM.from_pretrained("Ashok75/base2", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Ashok75/base2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Ashok75/base2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Ashok75/base2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Ashok75/base2
- SGLang
How to use Ashok75/base2 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Ashok75/base2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Ashok75/base2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Ashok75/base2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Ashok75/base2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Ashok75/base2 with Docker Model Runner:
docker model run hf.co/Ashok75/base2
Upload 28 files
Browse filesFiles changed (28)
- CODE_OF_CONDUCT.mdAdded+9
- LICENSEAdded+22
- README.mdAdded+218
- SECURITY.mdAdded+41
- added_tokens.jsonAdded+13
- auth.htmlAdded+1510
- chat.htmlAdded+1177
- config.jsonAdded+32
- data_summary_card.mdAdded+149
- file_pipeline.pyAdded+397
- generate.pyAdded+55
- generation_config.jsonAdded+11
- load_model.pyAdded+48
- model-00001-of-00006.safetensorsAdded+3
- model-00002-of-00006.safetensorsAdded+3
- model-00003-of-00006.safetensorsAdded+3
- model-00004-of-00006.safetensorsAdded+3
- model-00005-of-00006.safetensorsAdded+3
- model-00006-of-00006.safetensorsAdded+3
- model.safetensors.index.jsonAdded+250
- requirements.txtAdded+21
- run.pyAdded+221
- sample_finetune.pyAdded+214
- special_tokens_map.jsonAdded+23
- tokenizer.jsonAdded
- tokenizer.modelAdded+3
- tokenizer_config.jsonAdded+782
- vocab.jsonAdded
123456789# Microsoft Open Source Code of Conduct
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
Resources:
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns12345678910111213141516171819202122Microsoft.
Copyright (c) Microsoft Corporation.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218---license: mitlicense_link: https://huggingface.co/microsoft/Phi-4-reasoning/resolve/main/LICENSElanguage:- enbase_model:- microsoft/phi-4pipeline_tag: text-generationtags:- phi- nlp- math- code- chat- conversational- reasoninginference: parameters: temperature: 0widget:- messages: - role: user content: What is the derivative of x^2?library_name: transformers---
# Phi-4-reasoning Model Card
[Phi-4-reasoning Technical Report](https://huggingface.co/papers/2504.21318)
## Model Summary
| | | |-------------------------|-------------------------------------------------------------------------------|| **Developers** | Microsoft Research || **Description** | Phi-4-reasoning is a state-of-the-art open-weight reasoning model finetuned from Phi-4 using supervised fine-tuning on a dataset of chain-of-thought traces and reinforcement learning. The supervised fine-tuning dataset includes a blend of synthetic prompts and high-quality filtered data from public domain websites, focused on math, science, and coding skills as well as alignment data for safety and Responsible AI. The goal of this approach was to ensure that small capable models were trained with data focused on high quality and advanced reasoning. || **Architecture** | Base model same as previously released Phi-4, 14B parameters, dense decoder-only Transformer model || **Inputs** | Text, best suited for prompts in the chat format || **Context length** | 32k tokens || **GPUs** | 32 H100-80G || **Training time** | 2.5 days || **Training data** | 16B tokens, ~8.3B unique tokens || **Outputs** | Generated text in response to the input. Model responses have two sections, namely, a reasoning chain-of-thought block followed by a summarization block || **Dates** | January 2025 – April 2025 || **Status** | Static model trained on an offline dataset with cutoff dates of March 2025 and earlier for publicly available data || **Release date** | April 30, 2025 || **License** | MIT |
## Intended Use
| | ||-------------------------------|-------------------------------------------------------------------------|| **Primary Use Cases** | Our model is designed to accelerate research on language models, for use as a building block for generative AI powered features. It provides uses for general purpose AI systems and applications (primarily in English) which require:<br><br>1. Memory/compute constrained environments.<br>2. Latency bound scenarios.<br>3. Reasoning and logic. || **Out-of-Scope Use Cases** | This model is designed and tested for math reasoning only. Our models are not specifically designed or evaluated for all downstream purposes. Developers should consider common limitations of language models as they select use cases, and evaluate and mitigate for accuracy, safety, and fairness before using within a specific downstream use case, particularly for high-risk scenarios. Developers should be aware of and adhere to applicable laws or regulations (including privacy, trade compliance laws, etc.) that are relevant to their use case, including the model’s focus on English. Review the Responsible AI Considerations section below for further guidance when choosing a use case. Nothing contained in this Model Card should be interpreted as or deemed a restriction or modification to the license the model is released under. |
## Usage
> [!IMPORTANT] > To fully take advantage of the model's capabilities, inference must use `temperature=0.8`, `top_k=50`, `top_p=0.95`, and `do_sample=True`. For more complex queries, set `max_new_tokens=32768` to allow for longer chain-of-thought (CoT).
### Input Formats
Given the nature of the training data, **always use** ChatML template with the **following system prompt** for inference:
```bash<|im_start|>system<|im_sep|>You are Phi, a language model trained by Microsoft to help users. Your role as an assistant involves thoroughly exploring questions through a systematic thinking process before providing the final precise and accurate solutions. This requires engaging in a comprehensive cycle of analysis, summarizing, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. Please structure your response into two main sections: Thought and Solution using the specified format: <think> {Thought section} </think> {Solution section}. In the Thought section, detail your reasoning process in steps. Each step should include detailed considerations such as analysing questions, summarizing relevant findings, brainstorming new ideas, verifying the accuracy of the current steps, refining any errors, and revisiting previous steps. In the Solution section, based on various attempts, explorations, and reflections from the Thought section, systematically present the final solution that you deem correct. The Solution section should be logical, accurate, and concise and detail necessary steps needed to reach the conclusion. Now, try to solve the following question through the above guidelines:<|im_end|><|im_start|>user<|im_sep|>What is the derivative of x^2?<|im_end|><|im_start|>assistant<|im_sep|>```
### With `transformers`
```pythonfrom transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-4-reasoning")model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-4-reasoning", device_map="auto", torch_dtype="auto")
messages = [ {"role": "system", "content": "You are Phi, a language model trained by Microsoft to help users. Your role as an assistant involves thoroughly exploring questions through a systematic thinking process before providing the final precise and accurate solutions. This requires engaging in a comprehensive cycle of analysis, summarizing, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. Please structure your response into two main sections: Thought and Solution using the specified format: <think> {Thought section} </think> {Solution section}. In the Thought section, detail your reasoning process in steps. Each step should include detailed considerations such as analysing questions, summarizing relevant findings, brainstorming new ideas, verifying the accuracy of the current steps, refining any errors, and revisiting previous steps. In the Solution section, based on various attempts, explorations, and reflections from the Thought section, systematically present the final solution that you deem correct. The Solution section should be logical, accurate, and concise and detail necessary steps needed to reach the conclusion. Now, try to solve the following question through the above guidelines:"}, {"role": "user", "content": "What is the derivative of x^2?"},]inputs = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
outputs = model.generate( inputs.to(model.device), max_new_tokens=4096, temperature=0.8, top_k=50, top_p=0.95, do_sample=True,)print(tokenizer.decode(outputs[0]))```
### With `vllm`
```bashvllm serve microsoft/Phi-4-reasoning --enable-reasoning --reasoning-parser deepseek_r1```
*Phi-4-reasoning is also supported out-of-the-box by Ollama, llama.cpp, and any Phi-4 compatible framework.*
## Data Overview
### Training Datasets
Our training data is a mixture of Q&A, chat format data in math, science, and coding. The chat prompts are sourced from filtered high-quality web data and optionally rewritten and processed through a synthetic data generation pipeline. We further include data to improve truthfulness and safety.
### Benchmark Datasets
We evaluated Phi-4-reasoning using the open-source [Eureka](https://github.com/microsoft/eureka-ml-insights) evaluation suite and our own internal benchmarks to understand the model's capabilities. More specifically, we evaluate our model on:
Reasoning tasks:
* **AIME 2025, 2024, 2023, and 2022:** Math olympiad questions.
* **GPQA-Diamond:** Complex, graduate-level science questions.
* **OmniMath:** Collection of over 4000 olympiad-level math problems with human annotation.
* **LiveCodeBench:** Code generation benchmark gathered from competitive coding contests.
* **3SAT (3-literal Satisfiability Problem) and TSP (Traveling Salesman Problem):** Algorithmic problem solving.
* **BA Calendar:** Planning.
* **Maze and SpatialMap:** Spatial understanding.
General-purpose benchmarks:
* **Kitab:** Information retrieval.
* **IFEval and ArenaHard:** Instruction following.
* **PhiBench:** Internal benchmark.
* **FlenQA:** Impact of prompt length on model performance.
* **HumanEvalPlus:** Functional code generation.
* **MMLU-Pro:** Popular aggregated dataset for multitask language understanding.
## Safety
### Approach
Phi-4-reasoning has adopted a robust safety post-training approach via supervised fine-tuning (SFT). This approach leverages a variety of both open-source and in-house generated synthetic prompts, with LLM-generated responses that adhere to rigorous Microsoft safety guidelines, e.g., User Understanding and Clarity, Security and Ethical Guidelines, Limitations, Disclaimers and Knowledge Scope, Handling Complex and Sensitive Topics, Safety and Respectful Engagement, Confidentiality of Guidelines and Confidentiality of Chain-of-Thoughts.
### Safety Evaluation and Red-Teaming
Prior to release, Phi-4-reasoning followed a multi-faceted evaluation approach. Quantitative evaluation was conducted with multiple open-source safety benchmarks and in-house tools utilizing adversarial conversation simulation. For qualitative safety evaluation, we collaborated with the independent AI Red Team (AIRT) at Microsoft to assess safety risks posed by Phi-4-reasoning in both average and adversarial user scenarios. In the average user scenario, AIRT emulated typical single-turn and multi-turn interactions to identify potentially risky behaviors. The adversarial user scenario tested a wide range of techniques aimed at intentionally subverting the model's safety training including grounded-ness, jailbreaks, harmful content like hate and unfairness, violence, sexual content, or self-harm, and copyright violations for protected material. We further evaluate models on Toxigen, a benchmark designed to measure bias and toxicity targeted towards minority groups.
Please refer to the technical report for more details on safety alignment.
## Model Quality
At the high-level overview of the model quality on representative benchmarks. For the tables below, higher numbers indicate better performance:
| | AIME 24 | AIME 25 | OmniMath | GPQA-D | LiveCodeBench (8/1/24–2/1/25) ||-----------------------------|-------------|-------------|-------------|------------|-------------------------------|| Phi-4-reasoning | 75.3 | 62.9 | 76.6 | 65.8 | 53.8 || Phi-4-reasoning-plus | 81.3 | 78.0 | 81.9 | 68.9 | 53.1 || OpenThinker2-32B | 58.0 | 58.0 | — | 64.1 | — || QwQ 32B | 79.5 | 65.8 | — | 59.5 | 63.4 || EXAONE-Deep-32B | 72.1 | 65.8 | — | 66.1 | 59.5 || DeepSeek-R1-Distill-70B | 69.3 | 51.5 | 63.4 | 66.2 | 57.5 || DeepSeek-R1 | 78.7 | 70.4 | 85.0 | 73.0 | 62.8 || o1-mini | 63.6 | 54.8 | — | 60.0 | 53.8 || o1 | 74.6 | 75.3 | 67.5 | 76.7 | 71.0 || o3-mini | 88.0 | 78.0 | 74.6 | 77.7 | 69.5 || Claude-3.7-Sonnet | 55.3 | 58.7 | 54.6 | 76.8 | — || Gemini-2.5-Pro | 92.0 | 86.7 | 61.1 | 84.0 | 69.2 |
| | Phi-4 | Phi-4-reasoning | Phi-4-reasoning-plus | o3-mini | GPT-4o ||----------------------------------------|-------|------------------|-------------------|---------|--------|| FlenQA [3K-token subset] | 82.0 | 97.7 | 97.9 | 96.8 | 90.8 || IFEval Strict | 62.3 | 83.4 | 84.9 | 91.5 | 81.8 || ArenaHard | 68.1 | 73.3 | 79.0 | 81.9 | 75.6 || HumanEvalPlus | 83.5 | 92.9 | 92.3 | 94.0| 88.0 || MMLUPro | 71.5 | 74.3 | 76.0 | 79.4 | 73.0 || Kitab<br><small>No Context - Precision<br>With Context - Precision<br>No Context - Recall<br>With Context - Recall</small> | <br>19.3<br>88.5<br>8.2<br>68.1 | <br>23.2<br>91.5<br>4.9<br>74.8 | <br>27.6<br>93.6<br>6.3<br>75.4 | <br>37.9<br>94.0<br>4.2<br>76.1 | <br>53.7<br>84.7<br>20.3<br>69.2 || Toxigen Discriminative<br><small>Toxic category<br>Neutral category</small> | <br>72.6<br>90.0 | <br>86.7<br>84.7 | <br>77.3<br>90.5 | <br>85.4<br>88.7 | <br>87.6<br>85.1 || PhiBench 2.21 | 58.2 | 70.6 | 74.2 | 78.0| 72.4 |
Overall, Phi-4-reasoning, with only 14B parameters, performs well across a wide range of reasoning tasks, outperforming significantly larger open-weight models such as DeepSeek-R1 distilled 70B model and approaching the performance levels of full DeepSeek R1 model. We also test the models on multiple new reasoning benchmarks for algorithmic problem solving and planning, including 3SAT, TSP, and BA-Calendar. These new tasks are nominally out-of-domain for the models as the training process did not intentionally target these skills, but the models still show strong generalization to these tasks. Furthermore, when evaluating performance against standard general abilities benchmarks such as instruction following or non-reasoning tasks, we find that our new models improve significantly from Phi-4, despite the post-training being focused on reasoning skills in specific domains.
## Responsible AI Considerations
Like other language models, Phi-4-reasoning can potentially behave in ways that are unfair, unreliable, or offensive. Some of the limiting behaviors to be aware of include:
* **Quality of Service:** The model is trained primarily on English text. Languages other than English will experience worse performance. English language varieties with less representation in the training data might experience worse performance than standard American English. Phi-4-reasoning is not intended to support multilingual use.
* **Representation of Harms & Perpetuation of Stereotypes:** These models can over- or under-represent groups of people, erase representation of some groups, or reinforce demeaning or negative stereotypes. Despite safety post-training, these limitations may still be present due to differing levels of representation of different groups or prevalence of examples of negative stereotypes in training data that reflect real-world patterns and societal biases.
* **Inappropriate or Offensive Content:** These models may produce other types of inappropriate or offensive content, which may make it inappropriate to deploy for sensitive contexts without additional mitigations that are specific to the use case.
* **Information Reliability:** Language models can generate nonsensical content or fabricate content that might sound reasonable but is inaccurate or outdated.
* **Election Information Reliability:** The model has an elevated defect rate when responding to election-critical queries, which may result in incorrect or unauthoritative election critical information being presented. We are working to improve the model's performance in this area. Users should verify information related to elections with the election authority in their region.
* **Limited Scope for Code:** Majority of Phi-4-reasoning training data is based in Python and uses common packages such as `typing`, `math`, `random`, `collections`, `datetime`, `itertools`. If the model generates Python scripts that utilize other packages or scripts in other languages, we strongly recommend users manually verify all API uses.
Developers should apply responsible AI best practices and are responsible for ensuring that a specific use case complies with relevant laws and regulations (e.g. privacy, trade, etc.). Using safety services like [Azure AI Content Safety](https://azure.microsoft.com/en-us/products/ai-services/ai-content-safety) that have advanced guardrails is highly recommended. Important areas for consideration include:
* **Allocation:** Models may not be suitable for scenarios that could have consequential impact on legal status or the allocation of resources or life opportunities (ex: housing, employment, credit, etc.) without further assessments and additional debiasing techniques.
* **High-Risk Scenarios:** Developers should assess suitability of using models in high-risk scenarios where unfair, unreliable or offensive outputs might be extremely costly or lead to harm. This includes providing advice in sensitive or expert domains where accuracy and reliability are critical (ex: legal or health advice). Additional safeguards should be implemented at the application level according to the deployment context.
* **Misinformation:** Models may produce inaccurate information. Developers should follow transparency best practices and inform end-users they are interacting with an AI system. At the application level, developers can build feedback mechanisms and pipelines to ground responses in use-case specific, contextual information, a technique known as Retrieval Augmented Generation (RAG).
* **Generation of Harmful Content:** Developers should assess outputs for their context and use available safety classifiers or custom solutions appropriate for their use case.
* **Misuse:** Other forms of misuse such as fraud, spam, or malware production may be possible, and developers should ensure that their applications do not violate applicable laws and regulations.
* **Data Summary:** https://huggingface.co/microsoft/Phi-4-reasoning/blob/main/data_summary_card.md1234567891011121314151617181920212223242526272829303132333435363738394041<!-- BEGIN MICROSOFT SECURITY.MD V0.0.9 BLOCK -->
## Security
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet) and [Xamarin](https://github.com/xamarin).
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/security.md/definition), please report it to us as described below.
## Reporting Security Issues
**Please do not report security vulnerabilities through public GitHub issues.**
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/security.md/msrc/create-report).
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/security.md/msrc/pgp).
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue
This information will help us triage your report more quickly.
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/security.md/msrc/bounty) page for more details about our active programs.
## Preferred Languages
We prefer all communications to be in English.
## Policy
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/security.md/cvd).
<!-- END MICROSOFT SECURITY.MD BLOCK -->12345678910111213{
"<|endoftext|>": 32000,
"<|assistant|>": 32001,
"<|placeholder1|>": 32002,
"<|placeholder2|>": 32003,
"<|placeholder3|>": 32004,
"<|placeholder4|>": 32005,
"<|system|>": 32006,
"<|end|>": 32007,
"<|placeholder5|>": 32008,
"<|placeholder6|>": 32009,
"<|user|>": 32010
}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510<!DOCTYPE html><html lang="en" data-bs-theme="dark"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>GAKR AI - Login/Signup</title> <link rel="stylesheet" href="https://cdn.replit.com/agent/bootstrap-agent-dark-theme.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"> <style> :root { --gakr-blue: #4285F4; --gakr-blue-dark: #1a73e8; --gakr-blue-light: #e8f0fe; --gakr-grey-text: #5f6368; --gakr-grey-hover-bg: rgba(95, 99, 104, 0.1); }
:root[data-bs-theme="dark"] { --gakr-blue: #8ab4f8; --gakr-blue-dark: #669df6; --gakr-blue-light: rgba(138, 180, 248, 0.1); --gakr-grey-text: #bdc1c6; --gakr-grey-hover-bg: rgba(189, 193, 198, 0.1); }
@import url('https://fonts.googleapis.com/css?family=Poppins:400,500,600,700&display=swap');
* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Poppins', sans-serif; }
html, body { display: flex; flex-direction: column; align-items: center; height: 100%; width: 100%; background: -webkit-linear-gradient(left, #003366,#004080,#0059b3 , #0073e6); color: var(--bs-body-color); padding-top: 5vh; padding-bottom: 5vh; min-height: 100vh; /* Allow space for modal overlay */ position: relative; }
::selection { background: var(--gakr-blue); color: #fff; }
.wrapper { overflow: hidden; max-width: 440px; width: 90%; background: var(--bs-body-bg); box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.5); padding: 30px; border-radius: 15px; margin-top: 10px; margin-bottom: 10px; z-index: 10; /* Ensure wrapper is below modal but above background */ }
.wrapper .title-text { display: flex; width: 200%; }
.wrapper .title { width: 50%; font-size: 35px; font-weight: 600; text-align: center; transition: all 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55); color: var(--bs-body-color); }
.wrapper .slide-controls { position: relative; display: flex; height: 50px; width: 100%; overflow: hidden; margin: 30px 0 10px 0; justify-content: space-between; border: 1px solid var(--bs-border-color); border-radius: 15px; }
.slide-controls .slide { height: 100%; width: 100%; color: var(--bs-body-color); font-size: 18px; font-weight: 500; text-align: center; line-height: 48px; cursor: pointer; z-index: 1; transition: all 0.6s ease; }
.slide-controls label.signup{ color: var(--bs-body-color); }
.slide-controls .slider-tab { position: absolute; height: 100%; width: 50%; left: 0; z-index: 0; border-radius: 15px; background: var(--gakr-blue); transition: all 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55); }
input[type="radio"]{ display: none; }
#signup:checked ~ .slider-tab{ left: 50%; } #signup:checked ~ label.signup{ color: #fff; cursor: default; user-select: none; } #signup:checked ~ label.login{ color: var(--bs-body-color); } #login:checked ~ label.signup{ color: var(--bs-body-color); } #login:checked ~ label.login{ color: #fff; cursor: default; user-select: none; }
.wrapper .form-container { width: 100%; overflow: hidden; }
.form-container .form-inner { display: flex; width: 200%; }
.form-container .form-inner form { width: 50%; transition: all 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55); }
.form-inner form .field { height: 50px; width: 100%; margin-top: 20px; position: relative; }
.form-inner form .field:has(+ .field.btn) { margin-bottom: 25px; }
.form-inner form .field input{ height: 100%; width: 100%; outline: none; padding-left: 15px; border-radius: 15px; border: 1px solid var(--bs-border-color); border-bottom-width: 2px; font-size: 17px; transition: all 0.3s ease; color: var(--bs-body-color); background-color: var(--bs-body-bg); }
.form-inner form .field input.error { border-color: red; }
.form-inner form .field input::placeholder{ color: var(--bs-secondary-color); transition: all 0.3s ease; }
form .field input:focus::placeholder{ color: var(--gakr-blue); }
.form-inner form .pass-link{ margin-top: 5px; font-size: 0.9rem; text-align: right; /* Align to right */ }
.form-inner form .signup-link{ text-align: center; margin-top: 30px; font-size: 0.9rem; }
.form-inner form .pass-link a, .form-inner form .signup-link a{ color: var(--gakr-blue); text-decoration: none; transition: color 0.2s ease-in-out; }
.form-inner form .pass-link a:hover, form-inner form .signup-link a:hover{ text-decoration: underline; color: var(--gakr-blue-dark); }
form .btn { height: 50px; width: 100%; margin-top: 20px; border-radius: 15px; position: relative; overflow: hidden; background: none; transition: none; }
form .btn input[type="submit"] { height: 100%; width: 100%; z-index: 1; position: relative; background: var(--gakr-blue); border: none; color: #fff; padding: 0; border-radius: 15px; font-size: 20px; font-weight: 500; cursor: pointer; transition: background-color 0.2s ease-in-out, transform 0.1s ease-in-out; display: flex; align-items: center; justify-content: center; }
form .btn input[type="submit"]:hover { background-color: var(--gakr-blue-dark); }
form .btn input[type="submit"]:active { transform: scale(0.98); transition: background-color 0s, transform 0.1s; }
.error-message { color: red; font-size: 0.8rem; margin-top: 4px; position: absolute; bottom: -18px; left: 15px; white-space: nowrap; }
.form-message { text-align: center; margin-top: 20px; font-size: 0.9rem; min-height: 1.2em; }
.form-message.success { color: green; }
.form-message.error { color: red; }
.loading-spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid rgba(255, 255, 255, .3); border-radius: 50%; border-top-color: #fff; animation: spin 1s ease-in-out infinite; margin-left: 10px; vertical-align: middle; }
@keyframes spin { to { -webkit-transform: rotate(360deg); } }
.form-inner form .btn input[type="submit"]:disabled { opacity: 0.7; cursor: not-allowed; position: relative; }
/* --- Modal Styles --- */ .modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.6); /* Semi-transparent black overlay */ display: flex; justify-content: center; align-items: center; z-index: 100; /* On top of everything */ visibility: hidden; /* Hidden by default */ opacity: 0; transition: visibility 0s, opacity 0.3s ease-in-out; }
.modal-overlay.show { visibility: visible; opacity: 1; }
.modal-content { background-color: var(--bs-body-bg); padding: 30px; border-radius: 15px; box-shadow: 0px 5px 20px rgba(0, 0, 0, 0.7); text-align: center; max-width: 350px; width: 80%; transform: translateY(-20px); /* Slight animation on show */ transition: transform 0.3s ease-in-out; }
.modal-overlay.show .modal-content { transform: translateY(0); }
.modal-message { font-size: 1.1rem; margin-bottom: 25px; color: var(--bs-body-color); } .modal-message p { margin-bottom: 10px; /* Spacing for paragraphs in modal message */ line-height: 1.4; } .modal-message strong { font-size: 1.2rem; /* Heading for attempts message */ display: block; margin-bottom: 15px; } .modal-message ul { list-style: none; padding: 0; margin-bottom: 20px; } .modal-message ul li { margin-bottom: 8px; font-size: 1rem; }
.modal-button { background-color: var(--gakr-blue); color: #fff; border: none; padding: 10px 25px; border-radius: 10px; font-size: 1rem; cursor: pointer; transition: background-color 0.2s ease-in-out, transform 0.1s ease-in-out; }
.modal-button:hover { background-color: var(--gakr-blue-dark); }
.modal-button:active { transform: scale(0.98); } .modal-buttons-stacked { display: flex; flex-direction: column; /* Stack buttons vertically */ gap: 10px; margin-top: 20px; }
.modal-buttons-stacked .modal-button { width: 100%; /* Make buttons full width */ }
.modal-buttons-inline { display: flex; justify-content: space-between; /* Space them out */ gap: 15px; margin-top: 20px; } .modal-buttons-inline .modal-button { flex-grow: 1; /* Allow buttons to grow to fill space */ max-width: none; /* Override max-width from .modal-buttons */ }
/* Eye icon styles */ .field .toggle-password { position: absolute; right: 15px; top: 50%; transform: translateY(-50%); cursor: pointer; color: var(--bs-secondary-color); font-size: 0.9rem; }
.field .toggle-password:hover { color: var(--gakr-blue); }
/* Added styles for Forgot/Reset Modals */ .modal-form { text-align: left; margin-top: 20px; } .modal-form .field { margin-bottom: 15px; height: auto; /* Override default field height */ } .modal-form label { display: block; margin-bottom: 5px; font-size: 0.9rem; color: var(--bs-body-color); } .modal-form input[type="text"], .modal-form input[type="email"], .modal-form input[type="password"] { width: 100%; padding: 10px 15px; border: 1px solid var(--bs-border-color); border-radius: 10px; background-color: var(--bs-body-bg); color: var(--bs-body-color); box-sizing: border-box; /* Crucial for consistent width */ } .modal-form .error-message { position: static; /* Remove absolute positioning */ margin-top: 5px; margin-left: 0; white-space: normal; /* Allow message to wrap */ } .modal-buttons { display: flex; justify-content: center; gap: 15px; margin-top: 20px; } .modal-buttons button { width: 100%; max-width: 150px; } </style></head><body>
<div class="wrapper"> <div class="title-text"> <div class="title login">Login Form</div> <div class="title signup">Signup Form</div> </div> <div class="form-container"> <div class="slide-controls"> <input type="radio" name="slide" id="login" checked> <input type="radio" name="slide" id="signup"> <label for="login" class="slide login">Login</label> <label for="signup" class="slide signup">Signup</label> <div class="slider-tab"></div> </div> <div class="form-inner"> <form action="#" class="login" id="loginForm"> <div class="field"> <input type="text" placeholder="Username or Email" required id="loginUsernameOrEmail" name="username_or_email"> <div class="error-message" id="loginUsernameOrEmailError"></div> </div> <div class="field"> <input type="password" placeholder="Password" required id="loginPassword" name="password"> <span class="toggle-password fa-solid fa-eye-slash"></span> <div class="error-message" id="loginPasswordError"></div> </div> <div class="pass-link"><a href="#" id="forgotPasswordLink">Forgot password?</a></div> <div class="field btn"> <input type="submit" value="Login"> </div> <div class="signup-link">Not a member? <a href="">Signup now</a></div> </form> <form action="#" class="signup" id="signupForm"> <div class="field"> <input type="text" placeholder="Name" required id="signupName" name="name"> <div class="error-message" id="signupNameError"></div> </div> <div class="field"> <input type="text" placeholder="Email Address" required id="signupEmail" name="email"> <div class="error-message" id="signupEmailError"></div> </div> <div class="field"> <input type="password" placeholder="Password" required id="signupPassword" name="password"> <span class="toggle-password fa-solid fa-eye-slash"></span> <div class="error-message" id="signupPasswordError"></div> </div> <div class="field"> <input type="password" placeholder="Confirm password" required id="signupConfirmPassword" name="confirm_password"> <span class="toggle-password fa-solid fa-eye-slash"></span> <div class="error-message" id="signupConfirmPasswordError"></div> </div> <div class="field btn"> <input type="submit" value="Signup"> </div> </form> </div> </div> <div class="form-message" id="generalFormMessage"></div> </div>
<div class="modal-overlay" id="customModal"> <div class="modal-content"> <div class="modal-message" id="modalMessage"></div> <div id="modalButtonsContainer" class="modal-buttons"> </div> </div> </div>
<div class="modal-overlay" id="forgotPasswordRequestModal"> <div class="modal-content"> <p class="modal-message" id="forgotModalMessage">Enter your registered email to request a password reset.</p> <form id="forgotPasswordRequestForm" class="modal-form"> <div class="field"> <label for="forgotEmail">Email:</label> <input type="email" id="forgotEmail" name="email" required> <div class="error-message" id="forgotEmailError"></div> </div> <div class="modal-buttons-stacked"> <button type="submit" class="modal-button" id="forgotSubmitButton">Request OTP</button> <button type="button" class="modal-button" id="forgotCancelButton" style="background-color: var(--bs-secondary-color);">Cancel</button> </div> </form>
<div id="otpSection" style="display: none;"> <form id="verifyOtpForm" class="modal-form"> <div class="field"> <label for="otpInput">Enter OTP:</label> <input type="text" id="otpInput" name="otp" required maxlength="6" pattern="\d{6}" title="Please enter a 6-digit OTP"> <div class="error-message" id="otpError"></div> </div> <div class="modal-buttons-stacked"> <button type="submit" class="modal-button" id="verifyOtpButton">Verify OTP</button> <button type="button" class="modal-button" id="resendOtpButton" style="background-color: var(--bs-secondary-color);">Send Again</button> <button type="button" class="modal-button" id="otpCancelButton" style="background-color: var(--bs-secondary-color);">Cancel</button> </div> </form> </div> </div> </div>
<div class="modal-overlay" id="resetPasswordModal"> <div class="modal-content"> <p class="modal-message">Enter your new password.</p> <form id="resetPasswordForm" class="modal-form"> <div class="field"> <label for="resetEmail">Email:</label> <input type="email" id="resetEmail" name="email" required readonly style="background-color: var(--bs-secondary-bg); cursor: not-allowed;"> <div class="error-message" id="resetEmailError"></div> </div> <div class="field"> <label for="newPassword">New Password:</label> <input type="password" id="newPassword" name="new_password" required> <span class="toggle-password fa-solid fa-eye-slash"></span> <div class="error-message" id="newPasswordError"></div> </div> <div class="field"> <label for="confirmNewPassword">Confirm New Password:</label> <input type="password" id="confirmNewPassword" name="confirm_new_password" required> <span class="toggle-password fa-solid fa-eye-slash"></span> <div class="error-message" id="confirmNewPasswordError"></div> </div> <div class="modal-buttons-stacked"> <button type="submit" class="modal-button" id="resetSubmitButton">Reset Password</button> <button type="button" class="modal-button" id="resetCancelButton" style="background-color: var(--bs-secondary-color);">Cancel</button> </div> </form> </div> </div>
<script> document.addEventListener('DOMContentLoaded', function() { const loginText = document.querySelector(".title-text .login"); const loginFormDiv = document.querySelector("form.login"); const signupLink = document.querySelector("form .signup-link a"); const loginRadio = document.getElementById('login'); const signupRadio = document.getElementById('signup');
const loginForm = document.getElementById('loginForm'); const signupForm = document.getElementById('signupForm');
// Existing form inputs and error displays const loginUsernameOrEmailInput = document.getElementById('loginUsernameOrEmail'); const loginPasswordInput = document.getElementById('loginPassword'); const loginSubmitButton = loginForm ? loginForm.querySelector('input[type="submit"]') : null;
const signupNameInput = document.getElementById('signupName'); const signupEmailInput = document.getElementById('signupEmail'); const signupPasswordInput = document.getElementById('signupPassword'); const signupConfirmPasswordInput = document.getElementById('signupConfirmPassword'); const signupSubmitButton = signupForm ? signupForm.querySelector('input[type="submit"]') : null;
const loginUsernameOrEmailError = document.getElementById('loginUsernameOrEmailError'); const loginPasswordError = document.getElementById('loginPasswordError');
const signupNameError = document.getElementById('signupNameError'); const signupEmailError = document.getElementById('signupEmailError'); const signupPasswordError = document.getElementById('signupPasswordError'); const signupConfirmPasswordError = document.getElementById('signupConfirmPasswordError');
const generalFormMessage = document.getElementById('generalFormMessage');
// Modal elements (main alert modal) const customModal = document.getElementById('customModal'); const modalMessageDiv = document.getElementById('modalMessage'); const modalButtonsContainer = document.getElementById('modalButtonsContainer');
// Forgot Password Request & OTP Modals elements const forgotPasswordLink = document.getElementById('forgotPasswordLink'); const forgotPasswordRequestModal = document.getElementById('forgotPasswordRequestModal'); // The main overlay for forgot/otp const forgotModalMessage = document.getElementById('forgotModalMessage'); // Message within the forgot/otp modal
// Elements for Step 1: Request Email const forgotPasswordRequestForm = document.getElementById('forgotPasswordRequestForm'); const forgotEmailInput = document.getElementById('forgotEmail'); const forgotEmailError = document.getElementById('forgotEmailError'); const forgotSubmitButton = document.getElementById('forgotSubmitButton'); const forgotCancelButton = document.getElementById('forgotCancelButton');
// Elements for Step 2: Enter OTP const otpSection = document.getElementById('otpSection'); // The container for OTP input and buttons const verifyOtpForm = document.getElementById('verifyOtpForm'); const otpInput = document.getElementById('otpInput'); const otpError = document.getElementById('otpError'); const verifyOtpButton = document.getElementById('verifyOtpButton'); const resendOtpButton = document.getElementById('resendOtpButton'); const otpCancelButton = document.getElementById('otpCancelButton');
// Reset Password Modal elements (Step 3: New Password) const resetPasswordModal = document.getElementById('resetPasswordModal'); const resetPasswordForm = document.getElementById('resetPasswordForm'); const resetEmailInput = document.getElementById('resetEmail'); // Hidden but read-only email field const newPasswordInput = document.getElementById('newPassword'); const confirmNewPasswordInput = document.getElementById('confirmNewPassword'); const resetEmailError = document.getElementById('resetEmailError'); // Error for reset email (should be rare) const newPasswordError = document.getElementById('newPasswordError'); const confirmNewPasswordError = document.getElementById('confirmNewPasswordError'); const resetSubmitButton = document.getElementById('resetSubmitButton'); const resetCancelButton = document.getElementById('resetCancelButton');
// New: Login Attempt Counter let loginAttempts = 0; const MAX_LOGIN_ATTEMPTS = 3;
// Stores the email across the forgot password/OTP/reset flow let currentForgotEmail = '';
// Function to clear all error messages and input error classes function clearErrors(formType = 'all') { if (formType === 'all' || formType === 'main') { document.querySelectorAll('.error-message').forEach(el => el.textContent = ''); document.querySelectorAll('.form-inner form .field input').forEach(el => el.classList.remove('error')); if (generalFormMessage) { generalFormMessage.textContent = ''; generalFormMessage.className = 'form-message'; } } if (formType === 'all' || formType === 'forgot') { if (forgotEmailError) forgotEmailError.textContent = ''; if (forgotEmailInput) forgotEmailInput.classList.remove('error'); // Also clear the general forgotModalMessage when resetting for new flow if (forgotModalMessage) forgotModalMessage.innerHTML = 'Enter your registered email to request a password reset.'; } if (formType === 'all' || formType === 'otp') { if (otpError) otpError.textContent = ''; if (otpInput) otpInput.classList.remove('error'); } if (formType === 'all' || formType === 'reset') { if (resetEmailError) resetEmailError.textContent = ''; if (newPasswordError) newPasswordError.textContent = ''; if (confirmNewPasswordError) confirmNewPasswordError.textContent = ''; if (resetEmailInput) resetEmailInput.classList.remove('error'); if (newPasswordInput) newPasswordInput.classList.remove('error'); if (confirmNewPasswordInput) confirmNewPasswordInput.classList.remove('error'); } }
// Function to display general form-level message (below the forms) function displayFormMessage(message, type = 'info') { if (generalFormMessage) { generalFormMessage.textContent = message; generalFormMessage.className = 'form-message ' + type; } }
// Universal modal display function function showCustomModal(modalElement) { modalElement.classList.add('show'); }
// Universal modal hide function function hideCustomModal(modalElement) { modalElement.classList.remove('show'); clearErrors(); // Clear all errors when any modal is hidden }
// Function to show a flexible custom modal (for general alerts/info) function showFlexibleModal(messageHTML, buttonsConfig, callback = null) { modalMessageDiv.innerHTML = messageHTML; modalButtonsContainer.innerHTML = ''; // Clear previous buttons
if (buttonsConfig && buttonsConfig.length > 0) { const isInline = buttonsConfig.every(btn => !btn.newline); modalButtonsContainer.className = isInline ? 'modal-buttons-inline' : 'modal-buttons-stacked';
buttonsConfig.forEach(btnConf => { const button = document.createElement('button'); button.className = 'modal-button'; button.textContent = btnConf.text; if (btnConf.style) { button.style = btnConf.style; } button.onclick = function() { hideCustomModal(customModal); if (btnConf.action && typeof btnConf.action === 'function') { btnConf.action(); } if (callback && typeof callback === 'function') { callback(); } }; modalButtonsContainer.appendChild(button); }); } else { const okButton = document.createElement('button'); okButton.className = 'modal-button'; okButton.textContent = 'OK'; okButton.onclick = function() { hideCustomModal(customModal); if (callback && typeof callback === 'function') { callback(); } }; modalButtonsContainer.classList.remove('modal-buttons-inline', 'modal-buttons-stacked'); modalButtonsContainer.classList.add('modal-buttons'); modalButtonsContainer.appendChild(okButton); } showCustomModal(customModal); }
// Slide logic function slideToSignup() { if (loginFormDiv && loginText) { loginFormDiv.style.marginLeft = "-50%"; loginText.style.marginLeft = "-50%"; clearErrors('main'); } }
function slideToLogin() { if (loginFormDiv && loginText) { loginFormDiv.style.marginLeft = "0%"; loginText.style.marginLeft = "0%"; clearErrors('main'); } }
// Event listeners for radio buttons and signup link if (signupRadio) { signupRadio.addEventListener('change', function() { if (this.checked) { slideToSignup(); } }); }
if (loginRadio) { loginRadio.addEventListener('change', function() { if (this.checked) { slideToLogin(); } }); }
if (signupLink && signupRadio) { signupLink.onclick = ((e) => { e.preventDefault(); signupRadio.checked = true; slideToSignup(); }); }
// Handle URL parameter for initial tab const urlParams = new URLSearchParams(window.location.search); const showSignup = urlParams.get('signup');
if (showSignup === 'true') { if (signupRadio) { signupRadio.checked = true; slideToSignup(); } } else { if (loginRadio) { loginRadio.checked = true; slideToLogin(); } }
// Function to toggle password visibility function setupPasswordToggle(passwordInput, toggleIcon) { if (passwordInput && toggleIcon) { toggleIcon.addEventListener('click', function() { const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password'; passwordInput.setAttribute('type', type); this.classList.toggle('fa-eye'); this.classList.toggle('fa-eye-slash'); }); } }
// Setup password toggles for all password fields setupPasswordToggle(loginPasswordInput, document.querySelector('#loginForm .toggle-password')); setupPasswordToggle(signupPasswordInput, document.querySelector('#signupForm #signupPassword + .toggle-password')); setupPasswordToggle(signupConfirmPasswordInput, document.querySelector('#signupForm #signupConfirmPassword + .toggle-password')); setupPasswordToggle(newPasswordInput, document.querySelector('#resetPasswordForm #newPassword + .toggle-password')); setupPasswordToggle(confirmNewPasswordInput, document.querySelector('#resetPasswordForm #confirmNewPassword + .toggle-password'));
// Login Form Submission Handler if (loginForm) { loginForm.addEventListener('submit', function(event) { event.preventDefault(); clearErrors('main'); // Clear main form errors
// Only proceed if login attempts are below limit if (loginAttempts >= MAX_LOGIN_ATTEMPTS) { showLoginAttemptsLimitModal(); return; // Stop submission }
let isValid = true;
const usernameOrEmail = loginUsernameOrEmailInput.value.trim(); const password = loginPasswordInput.value.trim();
if (usernameOrEmail === '') { isValid = false; loginUsernameOrEmailError.textContent = 'Username or Email is required'; loginUsernameOrEmailInput.classList.add('error'); } if (password === '') { isValid = false; loginPasswordError.textContent = 'Password is required'; loginPasswordInput.classList.add('error'); }
if (isValid) { submitFormData(event.target, loginSubmitButton, '/api/login', 'main'); } }); }
// Signup Form Submission Handler if (signupForm) { signupForm.addEventListener('submit', function(event) { event.preventDefault(); clearErrors('main');
let isValid = true;
const name = signupNameInput.value.trim(); const email = signupEmailInput.value.trim(); const password = signupPasswordInput.value.trim(); const confirmPassword = signupConfirmPasswordInput.value.trim();
if (name === '') { isValid = false; signupNameError.textContent = 'Name is required'; signupNameInput.classList.add('error'); }
if (email === '') { isValid = false; signupEmailError.textContent = 'Email is required'; signupEmailInput.classList.add('error'); } else if (!isValidEmail(email)) { isValid = false; signupEmailError.textContent = 'Enter a valid email address'; signupEmailInput.classList.add('error'); }
if (password === '') { isValid = false; signupPasswordError.textContent = 'Password is required'; signupPasswordInput.classList.add('error'); } else if (password.length < 6) { isValid = false; signupPasswordError.textContent = 'Password must be at least 6 characters'; signupPasswordInput.classList.add('error'); }
if (confirmPassword === '') { isValid = false; signupConfirmPasswordError.textContent = 'Confirm password is required'; signupConfirmPasswordInput.classList.add('error'); } else if (password !== confirmPassword) { isValid = false; signupConfirmPasswordError.textContent = 'Passwords do not match'; signupConfirmPasswordInput.classList.add('error'); signupPasswordInput.classList.add('error'); }
if (isValid) { submitFormData(event.target, signupSubmitButton, '/api/signup', 'main'); } }); }
// Forgot Password Link Handler (Initial Click) if (forgotPasswordLink) { forgotPasswordLink.addEventListener('click', function(event) { event.preventDefault(); clearErrors('forgot'); // Clear errors for email request clearErrors('otp'); // Clear errors for OTP section
forgotPasswordRequestForm.reset(); // Clear email input otpInput.value = ''; // Clear OTP input // Reset the general message for the forgot password modal forgotModalMessage.innerHTML = 'Enter your registered email to request a password reset.';
// Show the email request form and hide the OTP section forgotPasswordRequestForm.style.display = 'block'; if (otpSection) otpSection.style.display = 'none'; // Ensure OTP section is hidden initially
showCustomModal(forgotPasswordRequestModal); }); }
// Step 1: Forgot Password Request Form Submission Handler (Requests OTP) if (forgotPasswordRequestForm) { forgotPasswordRequestForm.addEventListener('submit', async function(event) { event.preventDefault(); clearErrors('forgot'); // Clear errors specific to the email request form
let isValid = true; const email = forgotEmailInput.value.trim();
if (email === '') { isValid = false; forgotEmailError.textContent = 'Email is required.'; forgotEmailInput.classList.add('error'); } else if (!isValidEmail(email)) { isValid = false; forgotEmailError.textContent = 'Enter a valid email address.'; forgotEmailInput.classList.add('error'); }
if (isValid) { forgotSubmitButton.disabled = true; forgotSubmitButton.innerHTML = '<span class="loading-spinner"></span> Sending OTP...';
try { const response = await fetch('/api/forgot_password_request', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: email }) });
const result = await response.json();
if (response.ok) { currentForgotEmail = email; // Store email for subsequent steps
// Transition to OTP input section forgotPasswordRequestForm.style.display = 'none'; if (otpSection) otpSection.style.display = 'block'; otpInput.value = ''; // Clear previous OTP in case of resend
// Update message for OTP section let messageText = `<p>An OTP has been sent to <strong>${email}</strong>. Please enter it below.</p>`; // Note: Do not display simulated OTP in production. This is for testing convenience. // if (result.simulated_otp) { // messageText += `<p><strong>SIMULATED OTP (FOR TESTING):</strong> ${result.simulated_otp}</p>`; // } forgotModalMessage.innerHTML = messageText;
} else { displayModalFormErrors(result, forgotPasswordRequestForm, 'forgot'); } } catch (error) { console.error('Fetch error:', error); showFlexibleModal('<p>Network error. Could not request OTP. Please try again.</p>', [{ text: 'OK' }]); } finally { forgotSubmitButton.disabled = false; forgotSubmitButton.innerHTML = 'Request OTP'; } } }); }
// Step 2: OTP Verification Form Submission Handler if (verifyOtpForm) { verifyOtpForm.addEventListener('submit', async function(event) { event.preventDefault(); clearErrors('otp'); // Clear errors specific to the OTP verification form
let isValid = true; const otp = otpInput.value.trim();
if (otp === '') { isValid = false; otpError.textContent = 'OTP is required.'; otpInput.classList.add('error'); } else if (!/^\d{6}$/.test(otp)) { // Ensure it's 6 digits isValid = false; otpError.textContent = 'OTP must be a 6-digit number.'; otpInput.classList.add('error'); }
if (isValid) { verifyOtpButton.disabled = true; verifyOtpButton.innerHTML = '<span class="loading-spinner"></span> Verifying...';
try { const response = await fetch('/api/verify_otp', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: currentForgotEmail, otp: otp }) });
const result = await response.json();
if (response.ok) { hideCustomModal(forgotPasswordRequestModal); // Hide the OTP modal resetEmailInput.value = currentForgotEmail; // Pre-fill email in new password form newPasswordInput.value = ''; // Clear new password field confirmNewPasswordInput.value = ''; // Clear confirm new password field showCustomModal(resetPasswordModal); // Show the new password modal
} else { otpError.textContent = result.message || 'OTP verification failed.'; otpInput.classList.add('error'); otpInput.classList.add('error'); // Ensure input field is marked // Update the main message area of the OTP modal if a general message is returned if (result.message) { forgotModalMessage.innerHTML = `<p>${result.message}</p>`; } } } catch (error) { console.error('Fetch error:', error); showFlexibleModal('<p>Network error. Could not verify OTP. Please try again.</p>', [{ text: 'OK' }]); } finally { verifyOtpButton.disabled = false; verifyOtpButton.innerHTML = 'Verify OTP'; } } }); }
// Step 2: Resend OTP Button Handler if (resendOtpButton) { resendOtpButton.addEventListener('click', async function(event) { event.preventDefault(); clearErrors('otp'); // Clear any previous OTP errors resendOtpButton.disabled = true; resendOtpButton.innerHTML = '<span class="loading-spinner"></span> Resending...';
try { const response = await fetch('/api/forgot_password_request', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: currentForgotEmail }) });
const result = await response.json();
if (response.ok) { let messageText = `<p>New OTP sent to <strong>${currentForgotEmail}</strong>. Please enter it below.</p>`; // if (result.simulated_otp) { // Again, remove in production // messageText += `<p><strong>SIMULATED OTP (FOR TESTING):</strong> ${result.simulated_otp}</p>`; // } forgotModalMessage.innerHTML = messageText; otpInput.value = ''; // Clear previous OTP otpInput.classList.remove('error'); // Clear error state otpError.textContent = ''; // Clear error message } else { // If there's an error on resend, display it in the OTP section's error message otpError.textContent = result.message || 'Failed to resend OTP.'; otpInput.classList.add('error'); // Potentially highlight OTP input again if (result.message) { forgotModalMessage.innerHTML = `<p>${result.message}</p>`; } } } catch (error) { console.error('Fetch error:', error); showFlexibleModal('<p>Network error. Could not resend OTP. Please try again.</p>', [{ text: 'OK' }]); } finally { resendOtpButton.disabled = false; resendOtpButton.innerHTML = 'Send Again'; } }); }
// Handlers for Cancel buttons in the forgot/reset modals if (forgotCancelButton) { forgotCancelButton.addEventListener('click', function() { hideCustomModal(forgotPasswordRequestModal); forgotPasswordRequestForm.reset(); currentForgotEmail = ''; // Clear stored email clearErrors('forgot'); // Ensure all forgot-related errors are cleared }); }
if (otpCancelButton) { otpCancelButton.addEventListener('click', function() { hideCustomModal(forgotPasswordRequestModal); verifyOtpForm.reset(); currentForgotEmail = ''; // Clear stored email clearErrors('otp'); // Ensure all OTP-related errors are cleared }); }
if (resetCancelButton) { resetCancelButton.addEventListener('click', function() { hideCustomModal(resetPasswordModal); resetPasswordForm.reset(); currentForgotEmail = ''; // Clear stored email clearErrors('reset'); // Ensure all reset-related errors are cleared }); }
// Step 3: Reset Password Form Submission Handler if (resetPasswordForm) { resetPasswordForm.addEventListener('submit', async function(event) { event.preventDefault(); clearErrors('reset'); // Clear errors specific to the reset password form
let isValid = true; const email = resetEmailInput.value.trim(); // This should be currentForgotEmail const newPassword = newPasswordInput.value.trim(); const confirmNewPassword = confirmNewPasswordInput.value.trim();
if (email === '') { // Should be pre-filled, but a final check isValid = false; resetEmailError.textContent = 'Email is required.'; resetEmailInput.classList.add('error'); } else if (!isValidEmail(email)) { isValid = false; resetEmailError.textContent = 'Invalid email format.'; // Should not happen if pre-filled correctly resetEmailInput.classList.add('error'); }
if (newPassword === '') { isValid = false; newPasswordError.textContent = 'New password is required.'; newPasswordInput.classList.add('error'); } else if (newPassword.length < 6) { isValid = false; newPasswordError.textContent = 'New password must be at least 6 characters.'; newPasswordInput.classList.add('error'); }
if (confirmNewPassword === '') { isValid = false; confirmNewPasswordError.textContent = 'Confirm new password is required.'; confirmNewPasswordInput.classList.add('error'); } else if (newPassword !== confirmNewPassword) { isValid = false; confirmNewPasswordError.textContent = 'Passwords do not match.'; confirmNewPasswordInput.classList.add('error'); newPasswordInput.classList.add('error'); // Highlight both if they don't match }
if (isValid) { resetSubmitButton.disabled = true; resetSubmitButton.innerHTML = '<span class="loading-spinner"></span> Resetting...';
try { const response = await fetch('/api/reset_password', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: email, new_password: newPassword }) // Ensure correct variable name for new password });
const result = await response.json();
if (response.ok) { hideCustomModal(resetPasswordModal); resetPasswordForm.reset(); currentForgotEmail = ''; // Clear stored email after successful reset showFlexibleModal( '<p>Password reset successful. You can now login with your new password.</p>', [{ text: 'OK', action: () => { loginRadio.checked = true; slideToLogin(); }}] ); } else { // Display error messages from the backend displayModalFormErrors(result, resetPasswordForm, 'reset'); if (result.message && (result.message.includes('OTP not verified') || result.message.includes('not initiated'))) { showFlexibleModal( `<p>${result.message}</p><p>Please start the password reset process again.</p>`, [{ text: 'Start Over', action: () => { hideCustomModal(resetPasswordModal); forgotPasswordLink.click(); // Re-open the initial forgot password modal }}], null // No general callback ); } } } catch (error) { console.error('Fetch error:', error); showFlexibleModal('<p>Network error. Could not reset password. Please try again.</p>', [{ text: 'OK' }]); } finally { resetSubmitButton.disabled = false; resetSubmitButton.innerHTML = 'Reset Password'; } } }); }
// This function handles displaying errors from the backend for the main login/signup forms function handleMainFormErrors(result, formElement, endpoint) { if (endpoint === '/api/login') { if (result.message && (result.message.includes('Account not found') || result.message.includes('Invalid credentials'))) { showFlexibleModal( `<p>${result.message}</p><p>If you are not registered, please sign up.</p>`, [{ text: 'Sign Up', action: () => { signupRadio.checked = true; slideToSignup(); }}, { text: 'OK', style: 'background-color: var(--bs-secondary-color);' }] ); } } else if (endpoint === '/api/signup') { if (result.message && (result.message.includes('Email already registered') || result.message.includes('Username already taken'))) { showFlexibleModal( `<p>${result.message}</p><p>If you are already registered, please log in.</p>`, [{ text: 'Login', action: () => { loginRadio.checked = true; slideToLogin(); }}, { text: 'OK', style: 'background-color: var(--bs-secondary-color);' }] ); } } if (result.errors) { for (const field in result.errors) { let inputElement, errorElement;
if (formElement.id === 'loginForm' && field === 'username_or_email') { inputElement = loginUsernameOrEmailInput; errorElement = loginUsernameOrEmailError; } else if (formElement.id === 'signupForm' && field === 'name') { inputElement = signupNameInput; errorElement = signupNameError; } else { // This handles password errors for login and email/password for signup // Need to be careful with field names. Example: if backend returns 'password' for signup. inputElement = formElement.querySelector(`[name="${field}"]`); // This assumes predictable error element IDs based on input IDs const inputId = inputElement ? inputElement.id : null; errorElement = inputId ? document.getElementById(`${inputId}Error`) : null; }
if (errorElement) errorElement.textContent = result.errors[field]; if (inputElement) inputElement.classList.add('error'); } } }
// Generic function for handling errors in modals (forgot, otp, reset) function displayModalFormErrors(result, formElement, formContext) { // Clear errors specific to the current modal's form context clearErrors(formContext);
if (result.errors) { for (const field in result.errors) { // This is robust: Find the input element by its 'name' attribute const inputElement = formElement.querySelector(`[name="${field}"]`); // Then, find its associated error message element by looking for a sibling with the ID pattern const errorElement = inputElement ? document.getElementById(`${inputElement.id}Error`) : null;
if (errorElement) errorElement.textContent = result.errors[field]; if (inputElement) inputElement.classList.add('error'); } } // Update the main message area of the modal if a general message is returned const targetModalMessage = formElement.closest('.modal-content').querySelector('.modal-message'); if (targetModalMessage && result.message) { targetModalMessage.innerHTML = `<p>${result.message}</p>`; } }
// Main data submission function (unchanged for main forms, adapted for modals) async function submitFormData(formElement, submitButton, endpoint, formContext) { if (!formElement || !submitButton || !endpoint) { console.error("submitFormData called with missing arguments."); return; }
const formData = new FormData(formElement); const data = {}; for (let [key, value] of formData.entries()) { data[key] = value; }
submitButton.disabled = true; if (formContext === 'main') { displayFormMessage("Submitting...", 'info'); } else { // For modal buttons, update their innerHTML directly submitButton.innerHTML = '<span class="loading-spinner"></span> Submitting...'; }
try { const response = await fetch(endpoint, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(data), });
const result = await response.json();
if (response.ok) { if (formContext === 'main') { clearErrors('main'); formElement.reset(); displayFormMessage('', 'info'); // Clear "Submitting..." message loginAttempts = 0; // Reset login attempts on successful login
if (endpoint === '/api/signup') { showFlexibleModal( '<p>Registration successful! Please log in.</p>', [{ text: 'OK', action: () => { loginRadio.checked = true; slideToLogin(); const url = new URL(window.location); url.searchParams.delete('signup'); // Clean up URL window.history.replaceState({}, '', url.toString()); }}] ); } else if (endpoint === '/api/login') { showFlexibleModal( '<p>Login successful!</p>', [{ text: 'OK', action: () => { // Mark user as logged in so chat.html knows localStorage.setItem('gakr_is_logged_in', 'true'); alert('Welcome! You are logged in.'); // Optional: remove any guest flag if you had one // localStorage.removeItem('gakr_is_guest');
// Redirect back to chat interface window.location.href = 'chat.html'; } }] );}
} // For forgot/otp/reset, successful handling is now done directly in their respective event listeners // so no generic handling here for those contexts. } else { // Server returned an error (response.ok is false) if (formContext === 'main') { if (endpoint === '/api/login' && result.message && result.message.includes('Invalid credentials')) { loginAttempts++; loginPasswordInput.classList.add('error'); loginPasswordError.textContent = result.message;
if (loginAttempts >= MAX_LOGIN_ATTEMPTS) { showLoginAttemptsLimitModal(); loginPasswordInput.value = ''; // Clear password after max attempts } else { displayFormMessage(`Incorrect password. You have ${MAX_LOGIN_ATTEMPTS - loginAttempts} attempts left.`, 'error'); } } else { displayFormMessage(result.message || 'An error occurred.', 'error'); handleMainFormErrors(result, formElement, endpoint); } } else if (formContext === 'forgot') { displayModalFormErrors(result, formElement, 'forgot'); } else if (formContext === 'otp') { displayModalFormErrors(result, formElement, 'otp'); } else if (formContext === 'reset') { displayModalFormErrors(result, formElement, 'reset'); } } } catch (error) { console.error('Fetch error:', error); if (formContext === 'main') { displayFormMessage('Network error. Please try again.', 'error'); } else { showFlexibleModal( '<p>Network error. Please check your internet connection and try again.</p>', [{ text: 'OK' }] ); } } finally { submitButton.disabled = false; // Reset button text specifically for modal forms if not handled by success/error flows above if (formContext === 'forgot') { submitButton.innerHTML = 'Request OTP'; } else if (formContext === 'otp') { submitButton.innerHTML = 'Verify OTP'; } else if (formContext === 'reset') { submitButton.innerHTML = 'Reset Password'; } } }
function showLoginAttemptsLimitModal() { const messageHtml = ` <strong>You have made three incorrect login attempts.</strong> <ul> <li>1. If you are not registered, please <a href="#" id="modalSignupLink">sign up now</a>.</li> <li>2. If you are already registered, please <a href="#" id="modalLoginLink">login now</a> with correct credentials.</li> <li>3. If you have forgotten your password, click <a href="#" id="modalForgotPasswordLink">forgot password</a> to reset it.</li> </ul> `; const buttons = [ { text: 'Login', action: () => { loginRadio.checked = true; slideToLogin(); loginAttempts = 0; loginPasswordInput.value = ''; }}, { text: 'Signup', action: () => { signupRadio.checked = true; slideToSignup(); loginAttempts = 0; loginPasswordInput.value = ''; }} ];
showFlexibleModal(messageHtml, buttons, () => { const modalSignupLink = document.getElementById('modalSignupLink'); const modalLoginLink = document.getElementById('modalLoginLink'); const modalForgotPasswordLink = document.getElementById('modalForgotPasswordLink');
if (modalSignupLink) { modalSignupLink.onclick = (e) => { e.preventDefault(); hideCustomModal(customModal); signupRadio.checked = true; slideToSignup(); loginAttempts = 0; loginPasswordInput.value = ''; }; } if (modalLoginLink) { modalLoginLink.onclick = (e) => { e.preventDefault(); hideCustomModal(customModal); loginRadio.checked = true; slideToLogin(); loginAttempts = 0; loginPasswordInput.value = ''; }; } if (modalForgotPasswordLink) { modalForgotPasswordLink.onclick = (e) => { e.preventDefault(); hideCustomModal(customModal); forgotPasswordLink.click(); loginAttempts = 0; loginPasswordInput.value = ''; }; } }); }
function isValidEmail(email) { const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; return emailRegex.test(email); } });</script></body></html>1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177<!DOCTYPE html><html lang="en" data-bs-theme="dark"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>GAKR AI - Chat</title> <link rel="stylesheet" href="https://cdn.replit.com/agent/bootstrap-agent-dark-theme.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"> <link rel="stylesheet" href="style.css"> <style> /* --- Define CSS Variables (Copy from homepage or ensure in style.css) --- */ :root { /* Default light mode colors (adjust as needed) */ --gakr-blue: #4285F4; --gakr-blue-dark: #1a73e8; /* A slightly darker shade for active states */ --gakr-blue-light: #e8f0fe; /* A light shade for backgrounds */ --gakr-grey-text: #5f6368; --gakr-grey-hover-bg: rgba(95, 99, 104, 0.1); /* Subtle hover for grey icons */ }
:root[data-bs-theme="dark"] { /* Dark mode overrides (adjust based on your bootstrap dark theme vars) */ --gakr-blue: #8ab4f8; /* Lighter blue for dark mode */ --gakr-blue-dark: #669df6; --gakr-blue-light: rgba(138, 180, 248, 0.1); /* Light blue background with transparency */ --gakr-grey-text: #bdc1c6; --gakr-grey-hover-bg: rgba(189, 193, 198, 0.1); /* Ensure --bs-body-bg, --bs-body-color, --bs-border-color etc. are correctly set by bootstrap theme */ }
/* --- Base Chat Layout --- */ .gemini-chat-layout { display: flex; flex-direction: column; height: 100vh; width: 100%; background-color: var(--bs-body-bg); /* Use BS var */ color: var(--bs-body-color); /* Use BS var */ }
.gemini-chat-header { padding: 0.75rem 1.5rem; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--bs-border-color); height: 64px; }
.gemini-logo-area { display: flex; align-items: center; gap: 0.75rem; }
.gemini-brand-logo { width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; }
.gemini-brand-text { font-size: 1.25rem; font-weight: 500; color: var(--gakr-blue); }
.gemini-chat-wrapper { flex: 1; overflow: hidden; position: relative; display: flex; flex-direction: column; }
.gemini-chat-container { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 1.5rem; width: 100%; max-width: 800px; margin: 0 auto; }
.gemini-prompt-area { padding: 1rem; border-top: 1px solid var(--bs-border-color); width: 100%; max-width: 800px; margin: 0 auto; /* --- MODIFIED CSS: Add relative positioning for options container --- */ position: relative; /* --- END MODIFIED CSS --- */ }
.gemini-message { display: flex; flex-direction: column; gap: 0.5rem; max-width: 90%; }
.gemini-message-user { align-self: flex-end; }
.gemini-message-ai { align-self: flex-start; }
.gemini-message-header { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--bs-secondary-color); }
.gemini-message-avatar { width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; }
.gemini-message-content { padding: 1rem; border-radius: 12px; line-height: 1.5; /* Ensure text wrapping */ white-space: pre-wrap; word-break: break-word; }
.gemini-message-user .gemini-message-content { background-color: var(--bs-tertiary-bg); border-top-right-radius: 4px; }
.gemini-message-ai .gemini-message-content { background-color: rgba(66, 133, 244, 0.1); border-top-left-radius: 4px; }
.gemini-message-user .gemini-message-avatar { background-color: var(--bs-tertiary-bg); }
.gemini-message-ai .gemini-message-avatar { background-color: rgba(66, 133, 244, 0.2); color: var(--gakr-blue); }
/* --- MODIFIED CSS FOR INPUT/TEXTAREA AND ACTIONS --- */ .gemini-input-container { position: relative; /* Keep relative */ border-radius: 24px; border: 1px solid var(--bs-border-color); background: var(--bs-body-bg); padding: 0.75rem 1rem; /* Padding around content */ display: flex; /* --- MODIFIED: align-items to flex-end for textarea --- */ align-items: flex-end; /* --- END MODIFIED --- */ box-shadow: 0 1px 5px rgba(0,0,0,0.1); /* Added focus transition from homepage */ transition: border-color 0.3s ease-in-out, box-shadow 0.3s ease-in-out; flex-wrap: wrap; /* Allow items to wrap when attachments are added */ gap: 0.5rem; /* Space between attachments and input */ }
/* Style when the container or its children are focused */ .gemini-input-container:focus-within { border-color: var(--gakr-blue); box-shadow: 0 1px 8px rgba(66, 133, 244, 0.2); background: var(--bs-body-bg); }
/* Style the textarea (#userInput) */ .gemini-input { /* Targets the textarea with id="userInput" */ flex: 1; /* Textarea takes available space */ border: none; background: transparent; /* --- MODIFIED: Padding adjustment for textarea (removed initial padding to be controlled by JS) --- */ padding: 0; /* Changed from 0.5rem 0.5rem */ /* Removed fixed height: height: 24px; from previous input styles */ /* Removed fixed max-height: 120px; from chat page styles */ outline: none; color: var(--bs-body-color); font-size: 1rem; /* Keep font size */ resize: none; /* Prevent manual resizing */ overflow-y: hidden; /* JS manages this */ line-height: 1.4; /* Adjust line height as needed */ /* Min/Max height calculation (adjust if 1rem font size differs) */ min-height: calc(1rem * 1.4); /* Approx height of 1 line */ max-height: calc(1rem * 1.4 * 5); /* Approx max height (5 lines) */ box-sizing: border-box; /* Include padding/border in element size */ white-space: pre-wrap; /* Ensure text wraps */ word-break: break-word; /* Break long words */ vertical-align: bottom; /* Align baseline to bottom */ transition: height 0.3s ease-in-out; /* Animate height change */ }
.gemini-input:focus { outline: none; }
.gemini-input-actions { display: flex; /* --- MODIFIED: align-items to flex-end for textarea --- */ align-items: flex-end; /* --- ADDED: padding-bottom to align icons --- */ padding-bottom: 0px; /* Changed from 0.5rem, controlled by JS */ /* --- END MODIFIED --- */ gap: 0.5rem; font-size: 1.25rem; flex-shrink: 0; /* Prevent shrinking */ }
/* Reusing .gemini-action-button styles for new '+' button */ .gemini-action-button { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--bs-secondary-color); /* Use BS var */ /* Added hover/active transitions from homepage */ transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out; }
.gemini-action-button:hover { background-color: var(--bs-tertiary-bg); /* Use BS var */ color: var(--bs-body-color); /* Darken icon color slightly on hover */ }
.gemini-action-button:active { transform: scale(0.95); /* Slight press effect */ background-color: var(--bs-tertiary-bg); /* Keep hover bg on active */ color: var(--bs-body-color); transition: background-color 0s, transform 0.1s; /* Make feedback immediate */ }
.gemini-submit-button { color: var(--gakr-blue); /* Use CSS var */ }
/* Specific styles for submit button hover/active */ .gemini-submit-button:hover { background-color: var(--gakr-blue-light); /* Light blue background on hover */ color: var(--gakr-blue-dark); /* Darker blue icon on hover */ }
.gemini-submit-button:active { transform: scale(0.95); /* Slight press effect */ background-color: var(--gakr-blue-light); color: var(--gakr-blue-dark); transition: background-color 0s, transform 0.1s; }
.gemini-submit-button.disabled { opacity: 0.5; cursor: default; /* Ensure transitions are off when disabled to avoid weird states */ transition: none; }
.gemini-submit-button.disabled:hover { background-color: transparent; color: var(--gakr-blue); /* Keep original color when disabled */ } /* --- END MODIFIED CSS --- */
.gemini-typing { display: inline-flex; align-items: center; gap: 4px; padding: 0.75rem 1rem; border-radius: 12px; background-color: rgba(66, 133, 244, 0.1); margin-bottom: 1rem; align-self: flex-end; }
.gemini-typing-dot { width: 6px; height: 6px; border-radius: 50%; background-color: var(--gakr-blue); animation: typing 1.3s infinite ease-in-out; }
.gemini-typing-dot:nth-child(1) { animation-delay: 0s; } .gemini-typing-dot:nth-child(2) { animation-delay: 0.2s; } .gemini-typing-dot:nth-child(3) { animation-delay: 0.4s; }
.gemini-thinking-toggle { background: none; border: none; color: var(--gakr-blue); cursor: pointer; font-size: 0.9rem; padding: 0; margin-bottom: 0.5rem; text-decoration: underline; }
.gemini-thinking-content { display: block; margin-top: 0.5rem; padding: 0.5rem; background-color: rgba(138, 180, 248, 0.05); border-left: 3px solid var(--gakr-blue); font-style: italic; }
.gemini-welcome { text-align: center; max-width: 600px; margin: 4rem auto; }
.gemini-welcome-icon { font-size: 3rem; margin-bottom: 1.5rem; color: var(--gakr-blue); }
.gemini-welcome-title { font-size: 2rem; margin-bottom: 1rem; font-weight: 500; }
/* Login button styling (from homepage) */ .gemini-login-button { color: var(--gakr-blue); text-decoration: none; background: transparent; border: 1px solid var(--gakr-blue); padding: 0.5rem 1rem; border-radius: 50px; font-size: 0.9rem; transition: background-color 0.2s; }
.gemini-login-button:hover { background-color: rgba(66, 133, 244, 0.1); }
/* Login prompt modal (keep existing) */ .gemini-login-prompt { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; opacity: 0; visibility: hidden; transition: opacity 0.3s, visibility 0.3s; }
.gemini-login-prompt.show { opacity: 1; visibility: visible; }
.gemini-login-prompt-content { background-color: var(--bs-body-bg); border-radius: 12px; padding: 1.5rem; max-width: 400px; width: 90%; }
.gemini-login-prompt-title { font-size: 1.25rem; font-weight: 500; margin-bottom: 1rem; color: var(--gakr-blue); }
.gemini-login-prompt-buttons { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 1.5rem; }
.gemini-button-primary { background-color: var(--gakr-blue); color: white; border: none; padding: 0.75rem 1rem; border-radius: 50px; font-size: 0.9rem; text-align: center; text-decoration: none; cursor: pointer; transition: background-color 0.2s; }
.gemini-button-primary:hover { background-color: #3b78e7; }
.gemini-button-secondary { background-color: transparent; color: var(--gakr-blue); border: 1px solid var(--gakr-blue); padding: 0.75rem 1rem; border-radius: 50px; font-size: 0.9rem; text-align: center; text-decoration: none; cursor: pointer; transition: background-color 0.2s; }
.gemini-button-secondary:hover { background-color: rgba(66, 133, 244, 0.1); }
.gemini-button-text { background-color: transparent; color: var(--bs-body-color); border: none; padding: 0.75rem 1rem; border-radius: 50px; font-size: 0.9rem; text-align: center; text-decoration: none; cursor: pointer; transition: background-color 0.2s; }
.gemini-button-text:hover { background-color: var(--bs-tertiary-bg); }
/* --- NEW CSS for Attachment Options --- */ .attachment-options-container { position: absolute; bottom: 100%; /* Position above the input bar */ left: 1rem; /* Align with left edge padding of prompt area */ transform: translateY(-10px); /* Slight initial lift */ z-index: 10; /* Ensure it's above chat messages */
background-color: var(--bs-body-bg); border: 1px solid var(--bs-border-color); border-radius: 15px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); padding: 15px;
display: flex; gap: 20px; justify-content: flex-start; /* Align options to the left */ min-width: max-content;
opacity: 0; visibility: hidden; pointer-events: none; /* Prevent clicks when hidden */
transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out, visibility 0s linear 0.3s; /* Animate opacity/transform, hide visibility after */ }
/* State when visible */ .attachment-options-container.visible { opacity: 1; visibility: visible; pointer-events: auto; /* Allow clicks when visible */ transform: translateY(-20px); /* Slight slide up effect */ transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out, visibility 0s linear 0s; /* Show visibility immediately */ }
.attachment-option { display: flex; flex-direction: column; align-items: center; cursor: pointer; color: var(--bs-body-color); font-size: 0.8rem; gap: 5px; transition: color 0.2s ease-in-out; }
.attachment-option:hover { color: var(--gakr-blue); }
.attachment-icon { width: 48px; height: 48px; border-radius: 50%; background-color: var(--bs-tertiary-bg); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; transition: background-color 0.2s ease-in-out; }
.attachment-option:hover .attachment-icon { background-color: var(--gakr-blue-light); }
.attachment-text { text-align: center; }
/* Styles for attached file chips */ .attached-file-preview-container { display: flex; flex-wrap: wrap; gap: 8px; /* Removed padding-bottom from here, handled by JS setting padding-top on textarea */ width: 100%; /* Take full width of parent container */ }
.attached-file-chip { display: flex; align-items: center; background-color: var(--bs-tertiary-bg); border-radius: 16px; padding: 4px 8px; font-size: 0.85rem; color: var(--bs-body-color); max-width: 150px; /* Limit chip width */ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; position: relative; /* For the close button */ }
.attached-file-chip .file-name { flex-grow: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 8px; /* Space for close button */ }
.attached-file-chip .remove-file { cursor: pointer; margin-left: 4px; color: var(--bs-secondary-color); }
.attached-file-chip .remove-file:hover { color: var(--bs-body-color); }
.attached-file-chip img { width: 24px; height: 24px; border-radius: 4px; object-fit: cover; margin-right: 8px; }
/* Hide file inputs */ .hidden-file-input { display: none; }
/* --- END NEW CSS --- */
</style></head><body> <div class="gemini-chat-layout"> <header class="gemini-chat-header"> <div class="gemini-logo-area"> <a href="/" class="gemini-brand-logo"> <i class="fas fa-robot" style="color: var(--gakr-blue);"></i> </a> <a href="/" class="gemini-brand-text" style="text-decoration: none;">GAKR AI</a> </div>
<div class="gemini-nav-controls"> <a href="auth.html" class="gemini-login-button">Sign in / Register</a> </div> </header>
<div class="gemini-chat-wrapper"> <div class="gemini-chat-container" id="chatContainer"> <div class="gemini-welcome" id="welcomeMessage"> <div class="gemini-welcome-icon"> <i class="fas fa-robot"></i> </div> <h1 class="gemini-welcome-title">How can I help you today?</h1> <p>I'm GAKR AI, your AI assistant. Ask me anything!</p> </div>
<div class="gemini-message gemini-message-ai d-none" id="initialMessage"> <div class="gemini-message-header"> <div class="gemini-message-avatar"> <i class="fas fa-robot"></i> </div> <span>GAKR AI</span> </div> <div class="gemini-message-content">Hello! I'm GAKR AI How can I help you today? </div> </div>
<div class="gemini-typing d-none" id="typingIndicator"> <div class="gemini-typing-dot"></div> <div class="gemini-typing-dot"></div> <div class="gemini-typing-dot"></div> </div> </div>
<div class="gemini-prompt-area"> <div class="gemini-input-container" id="inputContainer"> <div class="gemini-action-button" id="addButton"> <i class="fas fa-plus"></i> </div> <div class="attached-file-preview-container" id="attachedFilePreviewContainer"> </div> <textarea class="gemini-input" id="userInput" placeholder="Message GAKR AI..." rows="1"></textarea>
<div class="gemini-input-actions"> <div class="gemini-action-button"> <i class="fas fa-microphone"></i> </div> <div class="gemini-action-button gemini-submit-button disabled" id="submitButton"> <i class="fas fa-arrow-right"></i> </div> </div> </div>
<div class="attachment-options-container"> <div class="attachment-option" id="cameraOption"> <div class="attachment-icon"><i class="fas fa-camera"></i></div> <div class="attachment-text">Camera</div> <input type="file" id="cameraInput" class="hidden-file-input" accept="image/*" capture="camera"> </div> <div class="attachment-option" id="galleryOption"> <div class="attachment-icon"><i class="fas fa-image"></i></div> <div class="attachment-text">Gallery</div> <input type="file" id="galleryInput" class="hidden-file-input" accept="image/*"> </div> <div class="attachment-option" id="filesOption"> <div class="attachment-icon"><i class="fas fa-paperclip"></i></div> <div class="attachment-text">Files</div> <input type="file" id="filesInput" class="hidden-file-input" accept="*/*"> </div> <div class="attachment-option" id="driveOption"> <div class="attachment-icon"><i class="fab fa-google-drive"></i></div> <div class="attachment-text">Drive</div> </div> </div> </div> </div>
<div class="gemini-login-prompt" id="loginPrompt"> <div class="gemini-login-prompt-content"> <div class="gemini-login-prompt-title">Continue with GAKR AI</div> <p>You've had 5 conversations with GAKR AI. Would you like to create an account to save your history?</p> <div class="gemini-login-prompt-buttons"> <a href="login.html" class="gemini-button-primary">Sign in</a> <a href="/login?signup=true" class="gemini-button-secondary">Create account</a> <button type="button" class="gemini-button-text" id="continueGuest">Continue as guest</button> </div> </div> </div> </div> <script>document.addEventListener('DOMContentLoaded', function() { const chatContainer = document.getElementById('chatContainer'); const userInput = document.getElementById('userInput'); // textarea const submitButton = document.getElementById('submitButton'); const typingIndicator = document.getElementById('typingIndicator'); const welcomeMessage = document.getElementById('welcomeMessage'); const initialMessage = document.getElementById('initialMessage'); const loginPrompt = document.getElementById('loginPrompt'); const continueGuest = document.getElementById('continueGuest');
const addButton = document.getElementById('addButton'); const attachmentOptionsContainer = document.querySelector('.attachment-options-container');
const cameraInput = document.getElementById('cameraInput'); const galleryInput = document.getElementById('galleryInput'); const filesInput = document.getElementById('filesInput'); const attachedFilePreviewContainer = document.getElementById('attachedFilePreviewContainer'); const inputContainer = document.getElementById('inputContainer');
let messageCount = 0; let attachedFiles = [];
// Simple login flag (set in auth flow: localStorage.setItem("gakr_is_logged_in","true")) const isLoggedIn = localStorage.getItem("gakr_is_logged_in") === "true";
// --- Textarea Auto-Grow & Scroll Logic (original, kept) --- const style = getComputedStyle(userInput); const lineHeight = parseFloat(style.lineHeight); const minHeight = lineHeight; const maxHeight = lineHeight * 5;
const initialInputContainerPaddingTop = parseFloat(getComputedStyle(inputContainer).paddingTop); const initialInputContainerPaddingBottom = parseFloat(getComputedStyle(inputContainer).paddingBottom); const initialActionButtonsHeight = document.querySelector('.gemini-input-actions').offsetHeight;
function autoGrowTextarea() { if (!userInput) { console.error("autoGrowTextarea called but userInput element not found."); return; }
userInput.style.height = 'auto'; const scrollHeight = userInput.scrollHeight;
let newTextareaHeight = Math.min(Math.max(scrollHeight, minHeight), maxHeight); userInput.style.height = newTextareaHeight + 'px';
if (attachedFiles.length > 0) { userInput.style.paddingTop = '0px'; userInput.style.paddingBottom = '0px'; inputContainer.style.alignItems = 'flex-start'; } else { userInput.style.paddingTop = '0px'; userInput.style.paddingBottom = '0px'; inputContainer.style.alignItems = 'flex-end'; }
if (scrollHeight > maxHeight) { userInput.style.overflowY = 'auto'; } else { userInput.style.overflowY = 'hidden'; }
// Prompt is required; files alone cannot send if (userInput.value.trim().length > 0) { submitButton.classList.remove('disabled'); } else { submitButton.classList.add('disabled'); } }
userInput.addEventListener('input', autoGrowTextarea); setTimeout(autoGrowTextarea, 0); // --- End Textarea Auto-Grow & Scroll Logic ---
// Handle Enter key for sending (Shift+Enter = newline) userInput.addEventListener('keydown', function(event) { if (event.key === 'Enter' && !event.shiftKey && !submitButton.classList.contains('disabled')) { event.preventDefault(); sendMessage(); } });
// Handle submit button click submitButton.addEventListener('click', function() { if (!this.classList.contains('disabled')) { sendMessage(); } });
// Existing “continue as guest” modal continueGuest.addEventListener('click', function() { loginPrompt.classList.remove('show'); });
// --- Handle Add Button Click --- addButton.addEventListener('click', function(event) { event.stopPropagation(); attachmentOptionsContainer.classList.toggle('visible'); });
// --- Attachment Options --- document.getElementById('cameraOption').addEventListener('click', function() { cameraInput.click(); attachmentOptionsContainer.classList.remove('visible'); });
document.getElementById('galleryOption').addEventListener('click', function() { galleryInput.click(); attachmentOptionsContainer.classList.remove('visible'); });
document.getElementById('filesOption').addEventListener('click', function() { filesInput.click(); attachmentOptionsContainer.classList.remove('visible'); });
document.getElementById('driveOption').addEventListener('click', function() { alert("Google Drive integration requires backend setup and Google API access."); attachmentOptionsContainer.classList.remove('visible'); });
// --- File input change (camera/gallery/files) --- [cameraInput, galleryInput, filesInput].forEach(input => { input.addEventListener('change', function(event) { const files = event.target.files; if (files.length > 0) { for (let i = 0; i < files.length; i++) { attachedFiles.push(files[i]); addFileChip(files[i]); } autoGrowTextarea(); userInput.focus(); } event.target.value = ''; }); });
function addFileChip(file) { const chip = document.createElement('div'); chip.className = 'attached-file-chip'; chip.setAttribute('data-filename', file.name);
let previewElement; if (file.type.startsWith('image/')) { const img = document.createElement('img'); img.src = URL.createObjectURL(file); img.alt = file.name; img.onload = () => URL.revokeObjectURL(img.src); previewElement = img; } else { const icon = document.createElement('i'); icon.className = 'fas fa-paperclip'; previewElement = icon; }
const fileNameSpan = document.createElement('span'); fileNameSpan.className = 'file-name'; fileNameSpan.textContent = file.name;
const removeButton = document.createElement('span'); removeButton.className = 'remove-file'; removeButton.innerHTML = '×'; removeButton.addEventListener('click', function() { removeFileChip(file.name); });
chip.appendChild(previewElement); chip.appendChild(fileNameSpan); chip.appendChild(removeButton);
attachedFilePreviewContainer.appendChild(chip); autoGrowTextarea(); }
function removeFileChip(filename) { const chipToRemove = attachedFilePreviewContainer.querySelector(`[data-filename="${filename}"]`); if (chipToRemove) { attachedFilePreviewContainer.removeChild(chipToRemove); attachedFiles = attachedFiles.filter(file => file.name !== filename); autoGrowTextarea(); } }
// Hide attachment options when clicking outside document.addEventListener('click', function(event) { const isClickInsideAddButton = addButton && addButton.contains(event.target); const isClickInsideOptions = attachmentOptionsContainer && attachmentOptionsContainer.contains(event.target);
if (attachmentOptionsContainer && attachmentOptionsContainer.classList.contains('visible') && !isClickInsideAddButton && !isClickInsideOptions) { attachmentOptionsContainer.classList.remove('visible'); } });
if (attachmentOptionsContainer) { attachmentOptionsContainer.addEventListener('click', function(event){ event.stopPropagation(); }); }
// --- Centered login reminder mini-window --- let inlineLoginPromptShown = false; function maybeShowInlineLoginPrompt() { if (isLoggedIn) return; if (inlineLoginPromptShown) return; if (messageCount % 5 !== 0) return;
inlineLoginPromptShown = true;
const overlay = document.createElement('div'); overlay.style.position = 'fixed'; overlay.style.inset = '0'; overlay.style.backgroundColor = 'rgba(0,0,0,0.35)'; overlay.style.display = 'flex'; overlay.style.alignItems = 'center'; overlay.style.justifyContent = 'center'; overlay.style.zIndex = '9999';
const card = document.createElement('div'); card.style.width = '100%'; card.style.maxWidth = '420px'; card.style.borderRadius = '16px'; card.style.backgroundColor = 'var(--bs-body-bg)'; card.style.border = '1px solid var(--bs-border-color)'; card.style.boxShadow = '0 16px 40px rgba(0,0,0,0.25)'; card.style.padding = '1.25rem 1.5rem'; card.style.display = 'flex'; card.style.flexDirection = 'column'; card.style.gap = '0.75rem';
const title = document.createElement('div'); title.textContent = "Save your conversations"; title.style.fontWeight = '600'; title.style.fontSize = '1rem';
const text = document.createElement('div'); text.textContent = "Log in to keep your chat history across devices. If you continue as a guest, your conversations may be lost later."; text.style.fontSize = '0.9rem'; text.style.opacity = '0.9';
const buttonRow = document.createElement('div'); buttonRow.style.display = 'flex'; buttonRow.style.gap = '0.75rem'; buttonRow.style.marginTop = '0.5rem';
const skipBtn = document.createElement('button'); skipBtn.textContent = "Continue without login"; skipBtn.style.flex = '1'; skipBtn.style.borderRadius = '999px'; skipBtn.style.border = '1px solid var(--bs-border-color)'; skipBtn.style.backgroundColor = 'transparent'; skipBtn.style.color = 'var(--bs-body-color)'; skipBtn.style.padding = '0.5rem 0.75rem'; skipBtn.style.fontSize = '0.85rem'; skipBtn.style.cursor = 'pointer';
const loginBtn = document.createElement('button'); loginBtn.textContent = "Log in to save chats"; loginBtn.style.flex = '1'; loginBtn.style.borderRadius = '999px'; loginBtn.style.border = 'none'; loginBtn.style.backgroundColor = 'var(--gakr-blue)'; loginBtn.style.color = '#fff'; loginBtn.style.padding = '0.5rem 0.75rem'; loginBtn.style.fontSize = '0.85rem'; loginBtn.style.cursor = 'pointer';
skipBtn.addEventListener('click', function () { overlay.remove(); });
loginBtn.addEventListener('click', function () { window.location.href = 'auth.html'; });
buttonRow.appendChild(skipBtn); buttonRow.appendChild(loginBtn); card.appendChild(title); card.appendChild(text); card.appendChild(buttonRow); overlay.appendChild(card); document.body.appendChild(overlay); }
// --- sendMessage: prompt required, files optional, generic error --- async function sendMessage() { const text = userInput.value.trim();
// Prompt is required; files alone cannot be sent if (!text) { return; }
if (!welcomeMessage.classList.contains('d-none')) { welcomeMessage.classList.add('d-none'); }
if (initialMessage.classList.contains('d-none')) { initialMessage.classList.remove('d-none'); }
const filesSnapshot = [...attachedFiles];
let userMessageContent = text; if (filesSnapshot.length > 0) { const fileNames = filesSnapshot.map(f => f.name).join(', '); userMessageContent += ` (Attached: ${fileNames})`; } addMessage(userMessageContent, 'user'); messageCount++;
userInput.value = ''; attachedFiles = []; attachedFilePreviewContainer.innerHTML = ''; autoGrowTextarea(); userInput.dispatchEvent(new Event('input', { bubbles: true }));
typingIndicator.classList.remove('d-none'); scrollToBottom();
const formData = new FormData(); formData.append('api_key', 'gakr-ai-2025-secret'); formData.append('prompt', text);
if (filesSnapshot.length > 0) { filesSnapshot.forEach((file) => { formData.append('files', file); }); }
try { const response = await fetch('/api/analyze', { method: 'POST', body: formData });
if (!response.ok) { typingIndicator.classList.add('d-none'); addMessage('There was a server issue. Please try again later.', 'ai'); return; }
// Create AI message div first const aiMessageDiv = addMessage('', 'ai', true); // true for streaming let accumulatedText = '';
const reader = response.body.getReader(); const decoder = new TextDecoder();
while (true) { const { done, value } = await reader.read(); if (done) break; const chunk = decoder.decode(value, { stream: true }); accumulatedText += chunk; updateAIMessage(aiMessageDiv, accumulatedText); }
if (messageCount > 0 && messageCount % 5 === 0) { maybeShowInlineLoginPrompt(); } } catch (error) { console.error('Fetch Error:', error); typingIndicator.classList.add('d-none'); addMessage('There was a server issue. Please try again later.', 'ai'); } finally { if (typingIndicator) { typingIndicator.classList.add('d-none'); } scrollToBottom(); } }
function addMessage(text, type, streaming = false) { const messageDiv = document.createElement('div'); messageDiv.className = `gemini-message gemini-message-${type}`;
const headerDiv = document.createElement('div'); headerDiv.className = 'gemini-message-header';
const avatarDiv = document.createElement('div'); avatarDiv.className = 'gemini-message-avatar';
const avatarIcon = document.createElement('i'); avatarIcon.className = type === 'user' ? 'fas fa-user' : 'fas fa-robot';
const nameSpan = document.createElement('span'); nameSpan.textContent = type === 'user' ? 'You' : 'GAKR AI';
const contentDiv = document.createElement('div'); contentDiv.className = 'gemini-message-content'; if (!streaming) { if (type === 'ai') { updateAIMessage(contentDiv, text); } else { contentDiv.textContent = text; } }
avatarDiv.appendChild(avatarIcon); headerDiv.appendChild(avatarDiv); headerDiv.appendChild(nameSpan);
messageDiv.appendChild(headerDiv); messageDiv.appendChild(contentDiv);
chatContainer.appendChild(messageDiv);
if (!streaming) { scrollToBottom(); }
return streaming ? contentDiv : null; }
function updateAIMessage(contentDiv, text) { // Clear previous content contentDiv.innerHTML = '';
const thinkStart = text.indexOf('<think>'); const thinkEnd = text.indexOf('</think>'); if (thinkStart !== -1 && thinkEnd !== -1 && thinkEnd > thinkStart) { const thinking = text.substring(thinkStart + 7, thinkEnd).trim(); const solution = text.substring(thinkEnd + 8).trim();
// Create toggle button const toggleButton = document.createElement('button'); toggleButton.className = 'gemini-thinking-toggle'; toggleButton.textContent = 'hide thinking'; toggleButton.onclick = function() { const thinkingDiv = this.nextElementSibling; if (thinkingDiv.style.display === 'none') { thinkingDiv.style.display = 'block'; this.textContent = 'hide thinking'; } else { thinkingDiv.style.display = 'none'; this.textContent = 'show thinking'; } };
// Create thinking content div const thinkingDiv = document.createElement('div'); thinkingDiv.className = 'gemini-thinking-content'; thinkingDiv.textContent = thinking;
contentDiv.appendChild(toggleButton); contentDiv.appendChild(thinkingDiv); contentDiv.appendChild(document.createTextNode(solution)); } else { contentDiv.textContent = text; } }
function scrollToBottom() { setTimeout(() => { if (chatContainer) { chatContainer.scrollTop = chatContainer.scrollHeight; } }, 0); }
// Initialize from URL ?q=... const urlParams = new URLSearchParams(window.location.search); const initialQuery = urlParams.get('q');
if (initialQuery) { userInput.value = initialQuery; userInput.dispatchEvent(new Event('input', { bubbles: true }));
setTimeout(function() { if (submitButton && !submitButton.classList.contains('disabled')) { submitButton.click(); } }, 100); } else { if (userInput) { if (userInput.value.trim().length === 0 && attachedFiles.length === 0) { if (submitButton) submitButton.classList.add('disabled'); } else { if (submitButton) submitButton.classList.remove('disabled'); } autoGrowTextarea(); } }});</script>
</body></html>1234567891011121314151617181920212223242526272829303132{ "architectures": [ "Phi3ForCausalLM" ], "attention_bias": false, "attention_dropout": 0.0, "bos_token_id": 100257, "embd_pdrop": 0.0, "eos_token_id": 100265, "hidden_act": "silu", "hidden_size": 5120, "initializer_range": 0.02, "intermediate_size": 17920, "max_position_embeddings": 32768, "model_type": "phi3", "num_attention_heads": 40, "num_hidden_layers": 40, "num_key_value_heads": 10, "original_max_position_embeddings": 32768, "pad_token_id": 100349, "partial_rotary_factor": 1.0, "resid_pdrop": 0.0, "rms_norm_eps": 1e-05, "rope_scaling": null, "rope_theta": 500000, "sliding_window": null, "tie_word_embeddings": false, "torch_dtype": "bfloat16", "transformers_version": "4.51.1", "use_cache": true, "vocab_size": 100352}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
# Data Summary for microsoft_Phi-4-reasoning
## 1. General information
**1.0.1 Version of the Summary:** 1.0
**1.0.2 Last update:** 24-Nov-2025
## 1.1 Model Developer Identification
**1.1.1 Model Developer name and contact details:** Microsoft Corporation at One Microsoft Way, Redmond, WA 98052. Tel: 425-882-8080
## 1.2 Model Identification
**1.2.1 Versioned model name(s):** Phi-4-reasoning
**1.2.2 Model release date:** 30-Apr-2025
## 1.3 Overall training data size and characteristics
### 1.3.1 Size of dataset and characteristics
**1.3.1.A Text training data size:** 1 billion to 1 trillion tokens
**1.3.1.B Text training data content:** Prompts sourced from publicly available websites, existing datasets, and licensed collections, augmented with synthetically generated problems; responses generated using o3-mini including chain-of-thought traces; includes STEM, coding, logical puzzles, and safety/Responsible AI alignment data
**1.3.1.C Image training data size:** Not applicable. Images are not part of the training data
**1.3.1.D Image training data content:** Not applicable
**1.3.1.E Audio training data size:** Not applicable. Audio data is not part of the training data
**1.3.1.F Audio training data content:** Not applicable
**1.3.1.G Video training data size:** Not applicable. Video data is not part of the training data
**1.3.1.H Video training data content:** Not applicable
**1.3.1.I Other training data size:** Not applicable
**1.3.1.J Other training data content:** Not applicable
**1.3.2 Latest date of data acquisition/collection for model training:** 31-Mar-2025
**1.3.3 Is data collection ongoing to update the model with new data collection after deployment?** No
**1.3.4 Date the training dataset was first used to train the model:** 01-Jan-2025
**1.3.5 Rationale or purpose of data selection:** Datasets were curated to emphasize complex multi-step reasoning and verifiable solutions across STEM, coding, and safety, selecting prompts at the boundary of base model capabilities. Synthetic problems and teacher-generated reasoning traces were used to distill structured chain-of-thought and promote concise, checkable answers, supporting robust reasoning performance and generalization to broader tasks
## 2. List of data sources
### 2.1 Publicly available datasets
**2.1.1 Have you used publicly available datasets to train the model?** Yes
## 2.2 Private non-publicly available datasets obtained from third parties
### 2.2.1 Datasets commercially licensed by rights holders or their representatives
**2.2.1.A Have you concluded transactional commercial licensing agreement(s) with rights holder(s) or with their representatives?** Yes
### 2.2.2 Private datasets obtained from other third-parties
**2.2.2.A Have you obtained private datasets from third parties that are not licensed as described in Section 2.2.1, such as data obtained from providers of private databases, or data intermediaries?** This information cannot be provided due to unavailability of the underlying data (e.g., loss, corruption, or other access limitations)
## 2.3 Personal Information
**2.3.1 Was personal data used to train the model?** Microsoft follows all relevant laws and regulations pertaining to personal information
## 2.4 Synthetic data
**2.4.1 Was any synthetic AI-generated data used to train the model?** Yes
## 3. Data processing aspects
### 3.1 Respect of reservation of rights from text and data mining exception or limitation
**3.1.1 Does this dataset include any data protected by copyright, trademark, or patent?** Microsoft follows all required regulations and laws for processing data protected by copyright, trademark, or patent
## 3.2 Other information
**3.2.1 Does the dataset include information about consumer groups without revealing individual consumer identities?** Microsoft follows all required regulations and laws for protecting consumer identities
**3.2.2 Was the dataset cleaned or modified before model training?** Yes
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397#!/usr/bin/env python3
"""
file_pipeline.py
Universal file pipeline for GAKR AI.
Responsibilities:
- Create dataupload/ folder structure (if not present)
- Save uploaded files to disk
- Detect file type
- Run type-specific extractors
- Return structured, text-friendly context for Phi-3
"""
from __future__ import annotations
import os
import mimetypes
from datetime import datetime
from typing import List, Dict, Any
import pandas as pd
import pdfplumber
import docx
import fitz # PyMuPDF
from PIL import Image
import pytesseract
import whisper
import ffmpeg
from fastapi import UploadFile
# ============================================================
# PATHS & FOLDERS
# ============================================================
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
UPLOAD_ROOT = os.path.join(BASE_DIR, "dataupload")
FOLDERS = {
"image": "images",
"video": "videos",
"audio": "audio",
"document": "documents",
"tabular": "tabular",
"other": "other",
}
def ensure_folders() -> None:
"""
Ensure base upload folder and all subfolders exist.
"""
os.makedirs(UPLOAD_ROOT, exist_ok=True)
for sub in FOLDERS.values():
os.makedirs(os.path.join(UPLOAD_ROOT, sub), exist_ok=True)
ensure_folders()
# ============================================================
# TYPE DETECTION & PATHS
# ============================================================
def detect_kind(filename: str, content_type: str | None) -> str:
"""
Decide logical kind: tabular, document, image, audio, video, other.
"""
ext = os.path.splitext(filename)[1].lower()
if ext in [".csv", ".xlsx", ".xls", ".json"]:
return "tabular"
if ext in [".pdf", ".txt"]:
return "document"
if ext in [".docx"]:
return "document"
if ext in [".png", ".jpg", ".jpeg", ".webp", ".bmp"]:
return "image"
if ext in [".mp3", ".wav", ".m4a"]:
return "audio"
if ext in [".mp4", ".mkv", ".mov", ".avi"]:
return "video"
if content_type:
if content_type.startswith("image/"):
return "image"
if content_type.startswith("audio/"):
return "audio"
if content_type.startswith("video/"):
return "video"
return "other"
def make_target_path(kind: str, filename: str) -> str:
"""
Build a safe, timestamped filepath under dataupload/{sub}/.
"""
sub = FOLDERS.get(kind, "other")
safe_name = os.path.basename(filename)
timestamp = datetime.utcnow().strftime("%Y%m%d_%H%M%S_%f")
final_name = f"{timestamp}_{safe_name}"
return os.path.join(UPLOAD_ROOT, sub, final_name)
# ============================================================
# MAIN MULTI-FILE ENTRY POINT
# ============================================================
async def process_files(files: List[UploadFile]) -> Dict[str, Any]:
"""
Save all files, run analyses, and return structured context.
Output example:
{
"files": [
{
"original_name": "...",
"stored_path": "dataupload/documents/...",
"kind": "document",
"summary": { ... }
},
...
]
}
"""
ensure_folders()
results: List[Dict[str, Any]] = []
for uf in files:
try:
kind = detect_kind(uf.filename, uf.content_type)
target_path = make_target_path(kind, uf.filename)
# Save file to disk
try:
with open(target_path, "wb") as out:
data = await uf.read()
out.write(data)
except Exception as save_err:
results.append(
{
"original_name": uf.filename,
"stored_path": None,
"kind": kind,
"summary": {
"error": f"Failed to save file: {save_err}"
},
}
)
continue
# Analyze by type
try:
summary = analyze_file(target_path, kind)
except Exception as analyze_err:
summary = {
"error": f"Unexpected error in analysis: {analyze_err}"
}
results.append(
{
"original_name": uf.filename,
"stored_path": os.path.relpath(target_path, BASE_DIR),
"kind": kind,
"summary": summary,
}
)
except Exception as outer_err:
results.append(
{
"original_name": getattr(uf, "filename", "unknown"),
"stored_path": None,
"kind": "unknown",
"summary": {
"error": f"Fatal error while handling file: {outer_err}"
},
}
)
return {"files": results}
# ============================================================
# TYPE-SPECIFIC ANALYSIS
# ============================================================
def analyze_file(path: str, kind: str) -> Dict[str, Any]:
if kind == "tabular":
return analyze_tabular(path)
if kind == "document":
return analyze_document(path)
if kind == "image":
return analyze_image(path)
if kind == "audio":
return analyze_audio(path)
if kind == "video":
return analyze_video(path)
return {"type": "other", "note": "Unsupported or unknown file type"}
# ---------- TABULAR: CSV / Excel / JSON ----------
def analyze_tabular(path: str) -> Dict[str, Any]:
ext = os.path.splitext(path)[1].lower()
df = None
try:
if ext == ".csv":
df = pd.read_csv(path)
elif ext in [".xlsx", ".xls"]:
df = pd.read_excel(path)
elif ext == ".json":
df = pd.read_json(path)
else:
return {
"type": "tabular",
"error": f"Unsupported tabular format: {ext}",
}
except Exception as e:
return {"type": "tabular", "error": f"Failed to load table: {e}"}
summary: Dict[str, Any] = {
"type": "tabular",
"rows": int(df.shape[0]),
"columns": [str(c) for c in df.columns],
}
try:
summary["missing_values"] = df.isna().sum().to_dict()
except Exception as e:
summary["missing_values_error"] = str(e)
try:
summary["numeric_stats"] = df.describe(include="number").to_dict()
except Exception:
summary["numeric_stats"] = {}
return summary
# ---------- DOCUMENTS: PDF / DOCX / TXT ----------
def analyze_document(path: str) -> Dict[str, Any]:
ext = os.path.splitext(path)[1].lower()
text = ""
try:
if ext == ".pdf":
# First try pdfplumber
try:
with pdfplumber.open(path) as pdf:
pages = []
for page in pdf.pages[:10]:
t = page.extract_text()
if t:
pages.append(t)
text = "\n".join(pages)
except Exception:
# Fallback to PyMuPDF
doc = fitz.open(path)
chunks = []
for page in doc[:10]:
chunks.append(page.get_text())
text = "\n".join(chunks)
elif ext == ".docx":
d = docx.Document(path)
paras = [p.text for p in d.paragraphs if p.text.strip()]
text = "\n".join(paras)
else: # .txt or unknown plain-text
with open(path, "r", encoding="utf-8", errors="ignore") as f:
text = f.read()
except Exception as e:
return {
"type": "document",
"error": f"Failed to extract document text: {e}",
}
short = text[:4000]
return {
"type": "document",
"char_count": len(text),
"preview": short,
}
# ---------- IMAGES ----------
def analyze_image(path: str) -> Dict[str, Any]:
try:
img = Image.open(path)
except Exception as e:
return {"type": "image", "error": f"Failed to open image: {e}"}
try:
text = pytesseract.image_to_string(img)
except Exception as e:
text = ""
ocr_error = str(e)
else:
ocr_error = None
short = text[:2000]
result: Dict[str, Any] = {
"type": "image",
"size": {"width": img.width, "height": img.height},
"ocr_preview": short,
}
if ocr_error:
result["ocr_error"] = ocr_error
return result
# ---------- AUDIO (Whisper) ----------
_whisper_model = None
def get_whisper_model():
global _whisper_model
if _whisper_model is None:
try:
_whisper_model = whisper.load_model("small")
except Exception as e:
raise RuntimeError(f"Failed to load Whisper model: {e}")
return _whisper_model
def analyze_audio(path: str) -> Dict[str, Any]:
try:
model = get_whisper_model()
except Exception as e:
return {"type": "audio", "error": str(e)}
try:
result = model.transcribe(path)
except Exception as e:
return {"type": "audio", "error": f"Whisper transcription failed: {e}"}
text = result.get("text", "") or ""
short = text[:4000]
duration = None
try:
if result.get("segments"):
duration = result["segments"][-1].get("end", None)
except Exception:
duration = None
return {
"type": "audio",
"duration_sec": duration,
"transcript_preview": short,
}
# ---------- VIDEO (audio extraction + Whisper) ----------
def analyze_video(path: str) -> Dict[str, Any]:
audio_path = path + ".tmp_audio.wav"
audio_summary: Dict[str, Any]
try:
(
ffmpeg
.input(path)
.output(audio_path, ac=1, ar=16000)
.overwrite_output()
.run(quiet=True)
)
except Exception as e:
return {
"type": "video",
"error": f"Failed to extract audio from video: {e}",
}
try:
audio_summary = analyze_audio(audio_path)
finally:
try:
if os.path.exists(audio_path):
os.remove(audio_path)
except Exception:
pass
return {
"type": "video",
"audio_analysis": audio_summary,
}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455# generate.py
import torch
from transformers import TextIteratorStreamer
from load_model import get_model
import threading
def generate_response(
user_prompt: str,
system_prompt: str = "You are a helpful AI assistant.",
max_tokens: int = 32768,
stream: bool = False,
) -> str:
"""Generate response using ALREADY LOADED model"""
model, tokenizer = get_model() # Fast - no loading!
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt},
]
input_ids = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
return_tensors="pt",
).to(model.device)
attention_mask = (input_ids != tokenizer.pad_token_id).long()
gen_kwargs = dict(
input_ids=input_ids,
attention_mask=attention_mask,
max_new_tokens=max_tokens,
pad_token_id=tokenizer.eos_token_id,
use_cache=False,
do_sample=True,
temperature=0.8,
top_k=50,
top_p=0.95,
)
if stream:
streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
gen_kwargs["streamer"] = streamer
thread = threading.Thread(target=model.generate, kwargs=gen_kwargs)
thread.start()
for text in streamer:
yield text
else:
with torch.no_grad():
outputs = model.generate(**gen_kwargs)
return tokenizer.decode(
outputs[0][input_ids.shape[1]:],
skip_special_tokens=True,
).strip()1234567891011{ "_from_model_config": true, "bos_token_id": 100257, "do_sample": true, "eos_token_id": 100265, "pad_token_id": 100349, "temperature": 0.8, "top_k": 50, "top_p": 0.95, "transformers_version": "4.51.1"}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748# load_model.py
import torch
import os
from transformers import AutoModelForCausalLM, AutoTokenizer
_model = None
_tokenizer = None
def init_model(model_dir: str = "."):
"""Call this ONCE at startup to load model into memory"""
global _model, _tokenizer
if _model is not None:
print("✅ Model already loaded!")
return _model, _tokenizer
device = "cuda" if torch.cuda.is_available() else "cpu"
if device == "cpu":
torch.set_num_threads(os.cpu_count())
print("\n" + "=" * 70)
print(f"Loading model from local files on {device.upper()}...")
print("=" * 70)
_model = AutoModelForCausalLM.from_pretrained(
model_dir,
device_map=device,
torch_dtype="auto",
trust_remote_code=True,
local_files_only=True,
)
_tokenizer = AutoTokenizer.from_pretrained(
model_dir,
local_files_only=True,
)
print(f"✅ Model loaded! ({sum(p.numel() for p in _model.parameters()) / 1e9:.1f}B params)")
print("=" * 70 + "\n")
return _model, _tokenizer
def get_model():
"""Get the already-loaded model (fast)"""
global _model, _tokenizer
if _model is None:
raise RuntimeError("Model not initialized! Call init_model() first.")
return _model, _tokenizer123version https://git-lfs.github.com/spec/v1oid sha256:ec6a22fa7bdb16f42be8ce5c08b36bacc0f3f865f2879cd364bb384413ada6b6size 4933656472123version https://git-lfs.github.com/spec/v1oid sha256:2fb9cce7c157ae2383bb65c129be64bff0f9d39a2fc0692bae478d14ea0e3232size 4954690712123version https://git-lfs.github.com/spec/v1oid sha256:ab647f44ed3e8dda48e9004dad07cfdca3ce12e463b4e9f78c2421813100083csize 4902241352123version https://git-lfs.github.com/spec/v1oid sha256:d8a37c74492fcacc8b6ae4329b0391002e597df169d7b4c1e9024dc99b3f1a7dsize 4771169120123version https://git-lfs.github.com/spec/v1oid sha256:ad7007b5aee76abab4561f757c586106d9ad934d0de9eec75f0d6211df6b2574size 4771169120123version https://git-lfs.github.com/spec/v1oid sha256:09f8f3d34d1610761ada4b6671f2a1971ed924dc636b964ebe26fb84efbdc3cesize 4986116216123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250{ "metadata": { "total_size": 29319014400 }, "weight_map": { "lm_head.weight": "model-00006-of-00006.safetensors", "model.embed_tokens.weight": "model-00001-of-00006.safetensors", "model.layers.0.input_layernorm.weight": "model-00001-of-00006.safetensors", "model.layers.0.mlp.down_proj.weight": "model-00001-of-00006.safetensors", "model.layers.0.mlp.gate_up_proj.weight": "model-00001-of-00006.safetensors", "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00006.safetensors", "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00006.safetensors", "model.layers.0.self_attn.qkv_proj.weight": "model-00001-of-00006.safetensors", "model.layers.1.input_layernorm.weight": "model-00001-of-00006.safetensors", "model.layers.1.mlp.down_proj.weight": "model-00001-of-00006.safetensors", "model.layers.1.mlp.gate_up_proj.weight": "model-00001-of-00006.safetensors", "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00006.safetensors", "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00006.safetensors", "model.layers.1.self_attn.qkv_proj.weight": "model-00001-of-00006.safetensors", "model.layers.10.input_layernorm.weight": "model-00002-of-00006.safetensors", "model.layers.10.mlp.down_proj.weight": "model-00002-of-00006.safetensors", "model.layers.10.mlp.gate_up_proj.weight": "model-00002-of-00006.safetensors", "model.layers.10.post_attention_layernorm.weight": "model-00002-of-00006.safetensors", "model.layers.10.self_attn.o_proj.weight": "model-00002-of-00006.safetensors", "model.layers.10.self_attn.qkv_proj.weight": "model-00002-of-00006.safetensors", "model.layers.11.input_layernorm.weight": "model-00002-of-00006.safetensors", "model.layers.11.mlp.down_proj.weight": "model-00002-of-00006.safetensors", "model.layers.11.mlp.gate_up_proj.weight": "model-00002-of-00006.safetensors", "model.layers.11.post_attention_layernorm.weight": "model-00002-of-00006.safetensors", "model.layers.11.self_attn.o_proj.weight": "model-00002-of-00006.safetensors", "model.layers.11.self_attn.qkv_proj.weight": "model-00002-of-00006.safetensors", "model.layers.12.input_layernorm.weight": "model-00002-of-00006.safetensors", "model.layers.12.mlp.down_proj.weight": "model-00002-of-00006.safetensors", "model.layers.12.mlp.gate_up_proj.weight": "model-00002-of-00006.safetensors", "model.layers.12.post_attention_layernorm.weight": "model-00002-of-00006.safetensors", "model.layers.12.self_attn.o_proj.weight": "model-00002-of-00006.safetensors", "model.layers.12.self_attn.qkv_proj.weight": "model-00002-of-00006.safetensors", "model.layers.13.input_layernorm.weight": "model-00003-of-00006.safetensors", "model.layers.13.mlp.down_proj.weight": "model-00003-of-00006.safetensors", "model.layers.13.mlp.gate_up_proj.weight": "model-00003-of-00006.safetensors", "model.layers.13.post_attention_layernorm.weight": "model-00003-of-00006.safetensors", "model.layers.13.self_attn.o_proj.weight": "model-00003-of-00006.safetensors", "model.layers.13.self_attn.qkv_proj.weight": "model-00003-of-00006.safetensors", "model.layers.14.input_layernorm.weight": "model-00003-of-00006.safetensors", "model.layers.14.mlp.down_proj.weight": "model-00003-of-00006.safetensors", "model.layers.14.mlp.gate_up_proj.weight": "model-00003-of-00006.safetensors", "model.layers.14.post_attention_layernorm.weight": "model-00003-of-00006.safetensors", "model.layers.14.self_attn.o_proj.weight": "model-00003-of-00006.safetensors", "model.layers.14.self_attn.qkv_proj.weight": "model-00003-of-00006.safetensors", "model.layers.15.input_layernorm.weight": "model-00003-of-00006.safetensors", "model.layers.15.mlp.down_proj.weight": "model-00003-of-00006.safetensors", "model.layers.15.mlp.gate_up_proj.weight": "model-00003-of-00006.safetensors", "model.layers.15.post_attention_layernorm.weight": "model-00003-of-00006.safetensors", "model.layers.15.self_attn.o_proj.weight": "model-00003-of-00006.safetensors", "model.layers.15.self_attn.qkv_proj.weight": "model-00003-of-00006.safetensors", "model.layers.16.input_layernorm.weight": "model-00003-of-00006.safetensors", "model.layers.16.mlp.down_proj.weight": "model-00003-of-00006.safetensors", "model.layers.16.mlp.gate_up_proj.weight": "model-00003-of-00006.safetensors", "model.layers.16.post_attention_layernorm.weight": "model-00003-of-00006.safetensors", "model.layers.16.self_attn.o_proj.weight": "model-00003-of-00006.safetensors", "model.layers.16.self_attn.qkv_proj.weight": "model-00003-of-00006.safetensors", "model.layers.17.input_layernorm.weight": "model-00003-of-00006.safetensors", "model.layers.17.mlp.down_proj.weight": "model-00003-of-00006.safetensors", "model.layers.17.mlp.gate_up_proj.weight": "model-00003-of-00006.safetensors", "model.layers.17.post_attention_layernorm.weight": "model-00003-of-00006.safetensors", "model.layers.17.self_attn.o_proj.weight": "model-00003-of-00006.safetensors", "model.layers.17.self_attn.qkv_proj.weight": "model-00003-of-00006.safetensors", "model.layers.18.input_layernorm.weight": "model-00003-of-00006.safetensors", "model.layers.18.mlp.down_proj.weight": "model-00003-of-00006.safetensors", "model.layers.18.mlp.gate_up_proj.weight": "model-00003-of-00006.safetensors", "model.layers.18.post_attention_layernorm.weight": "model-00003-of-00006.safetensors", "model.layers.18.self_attn.o_proj.weight": "model-00003-of-00006.safetensors", "model.layers.18.self_attn.qkv_proj.weight": "model-00003-of-00006.safetensors", "model.layers.19.input_layernorm.weight": "model-00003-of-00006.safetensors", "model.layers.19.mlp.down_proj.weight": "model-00003-of-00006.safetensors", "model.layers.19.mlp.gate_up_proj.weight": "model-00003-of-00006.safetensors", "model.layers.19.post_attention_layernorm.weight": "model-00003-of-00006.safetensors", "model.layers.19.self_attn.o_proj.weight": "model-00003-of-00006.safetensors", "model.layers.19.self_attn.qkv_proj.weight": "model-00003-of-00006.safetensors", "model.layers.2.input_layernorm.weight": "model-00001-of-00006.safetensors", "model.layers.2.mlp.down_proj.weight": "model-00001-of-00006.safetensors", "model.layers.2.mlp.gate_up_proj.weight": "model-00001-of-00006.safetensors", "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00006.safetensors", "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00006.safetensors", "model.layers.2.self_attn.qkv_proj.weight": "model-00001-of-00006.safetensors", "model.layers.20.input_layernorm.weight": "model-00004-of-00006.safetensors", "model.layers.20.mlp.down_proj.weight": "model-00004-of-00006.safetensors", "model.layers.20.mlp.gate_up_proj.weight": "model-00004-of-00006.safetensors", "model.layers.20.post_attention_layernorm.weight": "model-00004-of-00006.safetensors", "model.layers.20.self_attn.o_proj.weight": "model-00003-of-00006.safetensors", "model.layers.20.self_attn.qkv_proj.weight": "model-00003-of-00006.safetensors", "model.layers.21.input_layernorm.weight": "model-00004-of-00006.safetensors", "model.layers.21.mlp.down_proj.weight": "model-00004-of-00006.safetensors", "model.layers.21.mlp.gate_up_proj.weight": "model-00004-of-00006.safetensors", "model.layers.21.post_attention_layernorm.weight": "model-00004-of-00006.safetensors", "model.layers.21.self_attn.o_proj.weight": "model-00004-of-00006.safetensors", "model.layers.21.self_attn.qkv_proj.weight": "model-00004-of-00006.safetensors", "model.layers.22.input_layernorm.weight": "model-00004-of-00006.safetensors", "model.layers.22.mlp.down_proj.weight": "model-00004-of-00006.safetensors", "model.layers.22.mlp.gate_up_proj.weight": "model-00004-of-00006.safetensors", "model.layers.22.post_attention_layernorm.weight": "model-00004-of-00006.safetensors", "model.layers.22.self_attn.o_proj.weight": "model-00004-of-00006.safetensors", "model.layers.22.self_attn.qkv_proj.weight": "model-00004-of-00006.safetensors", "model.layers.23.input_layernorm.weight": "model-00004-of-00006.safetensors", "model.layers.23.mlp.down_proj.weight": "model-00004-of-00006.safetensors", "model.layers.23.mlp.gate_up_proj.weight": "model-00004-of-00006.safetensors", "model.layers.23.post_attention_layernorm.weight": "model-00004-of-00006.safetensors", "model.layers.23.self_attn.o_proj.weight": "model-00004-of-00006.safetensors", "model.layers.23.self_attn.qkv_proj.weight": "model-00004-of-00006.safetensors", "model.layers.24.input_layernorm.weight": "model-00004-of-00006.safetensors", "model.layers.24.mlp.down_proj.weight": "model-00004-of-00006.safetensors", "model.layers.24.mlp.gate_up_proj.weight": "model-00004-of-00006.safetensors", "model.layers.24.post_attention_layernorm.weight": "model-00004-of-00006.safetensors", "model.layers.24.self_attn.o_proj.weight": "model-00004-of-00006.safetensors", "model.layers.24.self_attn.qkv_proj.weight": "model-00004-of-00006.safetensors", "model.layers.25.input_layernorm.weight": "model-00004-of-00006.safetensors", "model.layers.25.mlp.down_proj.weight": "model-00004-of-00006.safetensors", "model.layers.25.mlp.gate_up_proj.weight": "model-00004-of-00006.safetensors", "model.layers.25.post_attention_layernorm.weight": "model-00004-of-00006.safetensors", "model.layers.25.self_attn.o_proj.weight": "model-00004-of-00006.safetensors", "model.layers.25.self_attn.qkv_proj.weight": "model-00004-of-00006.safetensors", "model.layers.26.input_layernorm.weight": "model-00004-of-00006.safetensors", "model.layers.26.mlp.down_proj.weight": "model-00004-of-00006.safetensors", "model.layers.26.mlp.gate_up_proj.weight": "model-00004-of-00006.safetensors", "model.layers.26.post_attention_layernorm.weight": "model-00004-of-00006.safetensors", "model.layers.26.self_attn.o_proj.weight": "model-00004-of-00006.safetensors", "model.layers.26.self_attn.qkv_proj.weight": "model-00004-of-00006.safetensors", "model.layers.27.input_layernorm.weight": "model-00005-of-00006.safetensors", "model.layers.27.mlp.down_proj.weight": "model-00005-of-00006.safetensors", "model.layers.27.mlp.gate_up_proj.weight": "model-00005-of-00006.safetensors", "model.layers.27.post_attention_layernorm.weight": "model-00005-of-00006.safetensors", "model.layers.27.self_attn.o_proj.weight": "model-00004-of-00006.safetensors", "model.layers.27.self_attn.qkv_proj.weight": "model-00004-of-00006.safetensors", "model.layers.28.input_layernorm.weight": "model-00005-of-00006.safetensors", "model.layers.28.mlp.down_proj.weight": "model-00005-of-00006.safetensors", "model.layers.28.mlp.gate_up_proj.weight": "model-00005-of-00006.safetensors", "model.layers.28.post_attention_layernorm.weight": "model-00005-of-00006.safetensors", "model.layers.28.self_attn.o_proj.weight": "model-00005-of-00006.safetensors", "model.layers.28.self_attn.qkv_proj.weight": "model-00005-of-00006.safetensors", "model.layers.29.input_layernorm.weight": "model-00005-of-00006.safetensors", "model.layers.29.mlp.down_proj.weight": "model-00005-of-00006.safetensors", "model.layers.29.mlp.gate_up_proj.weight": "model-00005-of-00006.safetensors", "model.layers.29.post_attention_layernorm.weight": "model-00005-of-00006.safetensors", "model.layers.29.self_attn.o_proj.weight": "model-00005-of-00006.safetensors", "model.layers.29.self_attn.qkv_proj.weight": "model-00005-of-00006.safetensors", "model.layers.3.input_layernorm.weight": "model-00001-of-00006.safetensors", "model.layers.3.mlp.down_proj.weight": "model-00001-of-00006.safetensors", "model.layers.3.mlp.gate_up_proj.weight": "model-00001-of-00006.safetensors", "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00006.safetensors", "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00006.safetensors", "model.layers.3.self_attn.qkv_proj.weight": "model-00001-of-00006.safetensors", "model.layers.30.input_layernorm.weight": "model-00005-of-00006.safetensors", "model.layers.30.mlp.down_proj.weight": "model-00005-of-00006.safetensors", "model.layers.30.mlp.gate_up_proj.weight": "model-00005-of-00006.safetensors", "model.layers.30.post_attention_layernorm.weight": "model-00005-of-00006.safetensors", "model.layers.30.self_attn.o_proj.weight": "model-00005-of-00006.safetensors", "model.layers.30.self_attn.qkv_proj.weight": "model-00005-of-00006.safetensors", "model.layers.31.input_layernorm.weight": "model-00005-of-00006.safetensors", "model.layers.31.mlp.down_proj.weight": "model-00005-of-00006.safetensors", "model.layers.31.mlp.gate_up_proj.weight": "model-00005-of-00006.safetensors", "model.layers.31.post_attention_layernorm.weight": "model-00005-of-00006.safetensors", "model.layers.31.self_attn.o_proj.weight": "model-00005-of-00006.safetensors", "model.layers.31.self_attn.qkv_proj.weight": "model-00005-of-00006.safetensors", "model.layers.32.input_layernorm.weight": "model-00005-of-00006.safetensors", "model.layers.32.mlp.down_proj.weight": "model-00005-of-00006.safetensors", "model.layers.32.mlp.gate_up_proj.weight": "model-00005-of-00006.safetensors", "model.layers.32.post_attention_layernorm.weight": "model-00005-of-00006.safetensors", "model.layers.32.self_attn.o_proj.weight": "model-00005-of-00006.safetensors", "model.layers.32.self_attn.qkv_proj.weight": "model-00005-of-00006.safetensors", "model.layers.33.input_layernorm.weight": "model-00005-of-00006.safetensors", "model.layers.33.mlp.down_proj.weight": "model-00005-of-00006.safetensors", "model.layers.33.mlp.gate_up_proj.weight": "model-00005-of-00006.safetensors", "model.layers.33.post_attention_layernorm.weight": "model-00005-of-00006.safetensors", "model.layers.33.self_attn.o_proj.weight": "model-00005-of-00006.safetensors", "model.layers.33.self_attn.qkv_proj.weight": "model-00005-of-00006.safetensors", "model.layers.34.input_layernorm.weight": "model-00006-of-00006.safetensors", "model.layers.34.mlp.down_proj.weight": "model-00006-of-00006.safetensors", "model.layers.34.mlp.gate_up_proj.weight": "model-00006-of-00006.safetensors", "model.layers.34.post_attention_layernorm.weight": "model-00006-of-00006.safetensors", "model.layers.34.self_attn.o_proj.weight": "model-00005-of-00006.safetensors", "model.layers.34.self_attn.qkv_proj.weight": "model-00005-of-00006.safetensors", "model.layers.35.input_layernorm.weight": "model-00006-of-00006.safetensors", "model.layers.35.mlp.down_proj.weight": "model-00006-of-00006.safetensors", "model.layers.35.mlp.gate_up_proj.weight": "model-00006-of-00006.safetensors", "model.layers.35.post_attention_layernorm.weight": "model-00006-of-00006.safetensors", "model.layers.35.self_attn.o_proj.weight": "model-00006-of-00006.safetensors", "model.layers.35.self_attn.qkv_proj.weight": "model-00006-of-00006.safetensors", "model.layers.36.input_layernorm.weight": "model-00006-of-00006.safetensors", "model.layers.36.mlp.down_proj.weight": "model-00006-of-00006.safetensors", "model.layers.36.mlp.gate_up_proj.weight": "model-00006-of-00006.safetensors", "model.layers.36.post_attention_layernorm.weight": "model-00006-of-00006.safetensors", "model.layers.36.self_attn.o_proj.weight": "model-00006-of-00006.safetensors", "model.layers.36.self_attn.qkv_proj.weight": "model-00006-of-00006.safetensors", "model.layers.37.input_layernorm.weight": "model-00006-of-00006.safetensors", "model.layers.37.mlp.down_proj.weight": "model-00006-of-00006.safetensors", "model.layers.37.mlp.gate_up_proj.weight": "model-00006-of-00006.safetensors", "model.layers.37.post_attention_layernorm.weight": "model-00006-of-00006.safetensors", "model.layers.37.self_attn.o_proj.weight": "model-00006-of-00006.safetensors", "model.layers.37.self_attn.qkv_proj.weight": "model-00006-of-00006.safetensors", "model.layers.38.input_layernorm.weight": "model-00006-of-00006.safetensors", "model.layers.38.mlp.down_proj.weight": "model-00006-of-00006.safetensors", "model.layers.38.mlp.gate_up_proj.weight": "model-00006-of-00006.safetensors", "model.layers.38.post_attention_layernorm.weight": "model-00006-of-00006.safetensors", "model.layers.38.self_attn.o_proj.weight": "model-00006-of-00006.safetensors", "model.layers.38.self_attn.qkv_proj.weight": "model-00006-of-00006.safetensors", "model.layers.39.input_layernorm.weight": "model-00006-of-00006.safetensors", "model.layers.39.mlp.down_proj.weight": "model-00006-of-00006.safetensors", "model.layers.39.mlp.gate_up_proj.weight": "model-00006-of-00006.safetensors", "model.layers.39.post_attention_layernorm.weight": "model-00006-of-00006.safetensors", "model.layers.39.self_attn.o_proj.weight": "model-00006-of-00006.safetensors", "model.layers.39.self_attn.qkv_proj.weight": "model-00006-of-00006.safetensors", "model.layers.4.input_layernorm.weight": "model-00001-of-00006.safetensors", "model.layers.4.mlp.down_proj.weight": "model-00001-of-00006.safetensors", "model.layers.4.mlp.gate_up_proj.weight": "model-00001-of-00006.safetensors", "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00006.safetensors", "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00006.safetensors", "model.layers.4.self_attn.qkv_proj.weight": "model-00001-of-00006.safetensors", "model.layers.5.input_layernorm.weight": "model-00002-of-00006.safetensors", "model.layers.5.mlp.down_proj.weight": "model-00002-of-00006.safetensors", "model.layers.5.mlp.gate_up_proj.weight": "model-00001-of-00006.safetensors", "model.layers.5.post_attention_layernorm.weight": "model-00002-of-00006.safetensors", "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00006.safetensors", "model.layers.5.self_attn.qkv_proj.weight": "model-00001-of-00006.safetensors", "model.layers.6.input_layernorm.weight": "model-00002-of-00006.safetensors", "model.layers.6.mlp.down_proj.weight": "model-00002-of-00006.safetensors", "model.layers.6.mlp.gate_up_proj.weight": "model-00002-of-00006.safetensors", "model.layers.6.post_attention_layernorm.weight": "model-00002-of-00006.safetensors", "model.layers.6.self_attn.o_proj.weight": "model-00002-of-00006.safetensors", "model.layers.6.self_attn.qkv_proj.weight": "model-00002-of-00006.safetensors", "model.layers.7.input_layernorm.weight": "model-00002-of-00006.safetensors", "model.layers.7.mlp.down_proj.weight": "model-00002-of-00006.safetensors", "model.layers.7.mlp.gate_up_proj.weight": "model-00002-of-00006.safetensors", "model.layers.7.post_attention_layernorm.weight": "model-00002-of-00006.safetensors", "model.layers.7.self_attn.o_proj.weight": "model-00002-of-00006.safetensors", "model.layers.7.self_attn.qkv_proj.weight": "model-00002-of-00006.safetensors", "model.layers.8.input_layernorm.weight": "model-00002-of-00006.safetensors", "model.layers.8.mlp.down_proj.weight": "model-00002-of-00006.safetensors", "model.layers.8.mlp.gate_up_proj.weight": "model-00002-of-00006.safetensors", "model.layers.8.post_attention_layernorm.weight": "model-00002-of-00006.safetensors", "model.layers.8.self_attn.o_proj.weight": "model-00002-of-00006.safetensors", "model.layers.8.self_attn.qkv_proj.weight": "model-00002-of-00006.safetensors", "model.layers.9.input_layernorm.weight": "model-00002-of-00006.safetensors", "model.layers.9.mlp.down_proj.weight": "model-00002-of-00006.safetensors", "model.layers.9.mlp.gate_up_proj.weight": "model-00002-of-00006.safetensors", "model.layers.9.post_attention_layernorm.weight": "model-00002-of-00006.safetensors", "model.layers.9.self_attn.o_proj.weight": "model-00002-of-00006.safetensors", "model.layers.9.self_attn.qkv_proj.weight": "model-00002-of-00006.safetensors", "model.norm.weight": "model-00006-of-00006.safetensors" }}123456789101112131415161718192021fastapi
uvicorn[standard]
python-multipart
torch
transformers
accelerate
safetensors
pandas
numpy
pdfplumber
pymupdf
python-docx
Pillow
pytesseract
openai-whisper
ffmpeg-python123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221#!/usr/bin/env python3"""run.py - FastAPI backend + frontend server for GAKR AI
Features:- Serves templates/chat.html at "/"- /api/analyze: - prompt: required (must not be empty) - files: optional list[UploadFile] (0, 1, many; any type) - api_key: required- If files are present → file-analysis mode (different system prompt)- If no files → general assistant mode- Detailed exceptions and logs for easier debugging"""
from typing import List, Optional
import jsonimport traceback
from fastapi import ( FastAPI, HTTPException, Form, UploadFile, File, Request,)from fastapi.middleware.cors import CORSMiddlewarefrom fastapi.responses import HTMLResponse, JSONResponse, StreamingResponsefrom fastapi.templating import Jinja2Templatesimport uvicorn
from load_model import init_modelfrom generate import generate_responsefrom file_pipeline import process_files
# ============================================================# APP SETUP# ============================================================
app = FastAPI(title="GAKR AI")
# Templates (chat.html lives in ./templates)templates = Jinja2Templates(directory="templates")
# CORS (open for dev; restrict origins in production)app.add_middleware( CORSMiddleware, allow_origins=["*"], # change to specific origin in production allow_credentials=True, allow_methods=["*"], allow_headers=["*"],)
# API KeyAPI_KEY = "gakr-ai-2025-secret"
# Load model ONCE at startupprint("🚀 Starting GAKR AI Backend...")try: model, tokenizer = init_model(".") print("✅ Model initialized successfully")except Exception as e: print("❌ Failed to load model at startup:") traceback.print_exc() raise e
# ============================================================# ROUTES# ============================================================
@app.get("/", response_class=HTMLResponse)async def home(request: Request): """ Serve chat.html as homepage. """ try: return templates.TemplateResponse("chat.html", {"request": request}) except Exception as e: # If template not found or other template error traceback.print_exc() raise HTTPException( status_code=500, detail=f"Failed to render chat.html: {str(e)}", )
@app.post("/api/analyze")async def analyze_endpoint( prompt: str = Form(...), # required api_key: str = Form(...), files: Optional[List[UploadFile]] = File(None), # optional): """ Main analysis endpoint.
Cases: - prompt only (no files) → general assistant mode - prompt + one/many files → file-analysis mode (uses file context) """ try: # ---------- Basic validation ---------- if api_key != API_KEY: raise HTTPException(status_code=401, detail="Invalid API key")
if prompt is None: raise HTTPException(status_code=400, detail="Prompt is missing") if not prompt.strip(): raise HTTPException(status_code=400, detail="Prompt cannot be empty")
files = files or []
# ---------- Branch by presence of files ---------- if files: # ----- CASE 1: prompt + files ----- try: context = await process_files(files) except Exception as extract_err: traceback.print_exc() raise HTTPException( status_code=500, detail=f"Error while processing uploaded files: {str(extract_err)}", )
context_text = json.dumps(context, indent=2, ensure_ascii=False) combined_user_prompt = f"""User question:{prompt}
Below is structured information extracted from the user's uploaded files.The extraction was done by automated tools.
Your task:1. Answer the user's question as accurately as possible.2. Use the context when it is relevant.3. Highlight important patterns, risks, or opportunities.4. If some information is missing or uncertain, say so honestly.
Context:{context_text}"""
system_prompt = ( "You are GAKR AI, a careful and honest analysis assistant that works with " "structured summaries of files (tables, PDFs, documents, images, audio, video, etc.). " "You never assume file contents beyond what the provided context states. " "You are a reasoning-focused AI assistant. " "Think carefully before answering. " "Provide clear, correct answers with brief explanations when helpful. " )
else: # ----- CASE 2: prompt only ----- context = {"files": []} # keep structure consistent combined_user_prompt = prompt
system_prompt = ( "You are GAKR AI, a reasoning-focused AI assistant. " "Think carefully before answering. " "Provide clear, correct answers with brief explanations when helpful. " )
# ---------- Generate with Phi-4 ---------- try: response_generator = generate_response( user_prompt=combined_user_prompt, system_prompt=system_prompt, max_tokens=32768, stream=True, ) except Exception as gen_err: traceback.print_exc() raise HTTPException( status_code=500, detail=f"Error during model generation: {str(gen_err)}", )
return StreamingResponse( response_generator, media_type="text/plain", )
except HTTPException: # Let FastAPI handle HTTPException as-is raise except Exception as e: # Unexpected error: log full traceback and return 500 traceback.print_exc() raise HTTPException( status_code=500, detail=f"Unexpected backend error: {str(e)}", )
@app.get("/health")async def health_check(): """ Simple health check. """ return {"status": "healthy", "model_loaded": True}
# ============================================================# ENTRY POINT# ============================================================
if __name__ == "__main__": print("\n" + "=" * 60) print("🌐 SERVER & CHAT LOCATION") print("=" * 60) print("🚀 CHAT INTERFACE: http://localhost:8080") print("📱 ALTERNATIVE URL: http://127.0.0.1:8080") print("🔧 API DOCUMENTATION: http://localhost:8080/docs") print("✅ CHAT.HTML SERVED: templates/chat.html") print("📁 TEMPLATES FOLDER: ./templates/") print("=" * 60 + "\n")
uvicorn.run(app, host="0.0.0.0", port=8080)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214import sysimport logging
import datasetsfrom datasets import load_datasetfrom peft import LoraConfigimport torchimport transformersfrom trl import SFTTrainerfrom transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments, BitsAndBytesConfig
"""A simple example on using SFTTrainer and Accelerate to finetune Phi-3 models. Fora more advanced example, please follow HF alignment-handbook/scripts/run_sft.py.This example has utilized DeepSpeed ZeRO3 offload to reduce the memory usage. Thescript can be run on V100 or later generation GPUs. Here are some suggestions on futher reducing memory consumption: - reduce batch size - decrease lora dimension - restrict lora target modulesPlease follow these steps to run the script:1. Install dependencies: conda install -c conda-forge accelerate pip3 install -i https://pypi.org/simple/ bitsandbytes pip3 install peft transformers trl datasets pip3 install deepspeed2. Setup accelerate and deepspeed config based on the machine used: accelerate configHere is a sample config for deepspeed zero3: compute_environment: LOCAL_MACHINE debug: false deepspeed_config: gradient_accumulation_steps: 1 offload_optimizer_device: none offload_param_device: none zero3_init_flag: true zero3_save_16bit_model: true zero_stage: 3 distributed_type: DEEPSPEED downcast_bf16: 'no' enable_cpu_affinity: false machine_rank: 0 main_training_function: main mixed_precision: bf16 num_machines: 1 num_processes: 4 rdzv_backend: static same_network: true tpu_env: [] tpu_use_cluster: false tpu_use_sudo: false use_cpu: false3. check accelerate config: accelerate env4. Run the code: accelerate launch sample_finetune.py"""
logger = logging.getLogger(__name__)
#################### Hyper-parameters###################training_config = { "bf16": True, "do_eval": False, "learning_rate": 5.0e-06, "log_level": "info", "logging_steps": 20, "logging_strategy": "steps", "lr_scheduler_type": "cosine", "num_train_epochs": 1, "max_steps": -1, "output_dir": "./checkpoint_dir", "overwrite_output_dir": True, "per_device_eval_batch_size": 4, "per_device_train_batch_size": 4, "remove_unused_columns": True, "save_steps": 100, "save_total_limit": 1, "seed": 0, "gradient_checkpointing": True, "gradient_checkpointing_kwargs":{"use_reentrant": False}, "gradient_accumulation_steps": 1, "warmup_ratio": 0.2, }
peft_config = { "r": 16, "lora_alpha": 32, "lora_dropout": 0.05, "bias": "none", "task_type": "CAUSAL_LM", "target_modules": "all-linear", "modules_to_save": None,}train_conf = TrainingArguments(**training_config)peft_conf = LoraConfig(**peft_config)
################ Setup logging###############logging.basicConfig( format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S", handlers=[logging.StreamHandler(sys.stdout)],)log_level = train_conf.get_process_log_level()logger.setLevel(log_level)datasets.utils.logging.set_verbosity(log_level)transformers.utils.logging.set_verbosity(log_level)transformers.utils.logging.enable_default_handler()transformers.utils.logging.enable_explicit_format()
# Log on each process a small summarylogger.warning( f"Process rank: {train_conf.local_rank}, device: {train_conf.device}, n_gpu: {train_conf.n_gpu}" + f" distributed training: {bool(train_conf.local_rank != -1)}, 16-bits training: {train_conf.fp16}")logger.info(f"Training/evaluation parameters {train_conf}")logger.info(f"PEFT parameters {peft_conf}")
################# Model Loading################
checkpoint_path = "microsoft/Phi-3.5-mini-instruct"model_kwargs = dict( use_cache=False, trust_remote_code=True, attn_implementation="flash_attention_2", # loading the model with flash-attenstion support torch_dtype=torch.bfloat16, device_map=None)model = AutoModelForCausalLM.from_pretrained(checkpoint_path, **model_kwargs)tokenizer = AutoTokenizer.from_pretrained(checkpoint_path)tokenizer.model_max_length = 2048tokenizer.pad_token = tokenizer.unk_token # use unk rather than eos token to prevent endless generationtokenizer.pad_token_id = tokenizer.convert_tokens_to_ids(tokenizer.pad_token)tokenizer.padding_side = 'right'
################### Data Processing##################def apply_chat_template( example, tokenizer,): messages = example["messages"] example["text"] = tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=False) return example
raw_dataset = load_dataset("HuggingFaceH4/ultrachat_200k")train_dataset = raw_dataset["train_sft"]test_dataset = raw_dataset["test_sft"]column_names = list(train_dataset.features)
processed_train_dataset = train_dataset.map( apply_chat_template, fn_kwargs={"tokenizer": tokenizer}, num_proc=10, remove_columns=column_names, desc="Applying chat template to train_sft",)
processed_test_dataset = test_dataset.map( apply_chat_template, fn_kwargs={"tokenizer": tokenizer}, num_proc=10, remove_columns=column_names, desc="Applying chat template to test_sft",)
############ Training###########trainer = SFTTrainer( model=model, args=train_conf, peft_config=peft_conf, train_dataset=processed_train_dataset, eval_dataset=processed_test_dataset, max_seq_length=2048, dataset_text_field="text", tokenizer=tokenizer, packing=True)train_result = trainer.train()metrics = train_result.metricstrainer.log_metrics("train", metrics)trainer.save_metrics("train", metrics)trainer.save_state()
############## Evaluation#############tokenizer.padding_side = 'left'metrics = trainer.evaluate()metrics["eval_samples"] = len(processed_test_dataset)trainer.log_metrics("eval", metrics)trainer.save_metrics("eval", metrics)
# ############# # Save model# ############trainer.save_model(train_conf.output_dir)1234567891011121314151617181920212223{ "bos_token": { "content": "<|endoftext|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false }, "eos_token": { "content": "<|im_end|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false }, "pad_token": { "content": "<|dummy_85|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false }}123version https://git-lfs.github.com/spec/v1oid sha256:9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347size 499723123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782{ "add_prefix_space": false, "added_tokens_decoder": { "100256": { "content": "<|dummy_0|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100257": { "content": "<|endoftext|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100258": { "content": "<|fim_prefix|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": false }, "100259": { "content": "<|fim_middle|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": false }, "100260": { "content": "<|fim_suffix|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": false }, "100261": { "content": "<|dummy_1|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100262": { "content": "<|dummy_2|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100263": { "content": "<|dummy_3|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100264": { "content": "<|im_start|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100265": { "content": "<|im_end|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100266": { "content": "<|im_sep|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100267": { "content": "<|dummy_4|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100268": { "content": "<|dummy_5|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100269": { "content": "<|dummy_6|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100270": { "content": "<|dummy_7|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100271": { "content": "<|dummy_8|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100272": { "content": "<|dummy_9|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100273": { "content": "<|dummy_10|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100274": { "content": "<|dummy_11|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100275": { "content": "<|dummy_12|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100276": { "content": "<|endofprompt|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100277": { "content": "<|dummy_13|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100278": { "content": "<|dummy_14|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100279": { "content": "<|dummy_15|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100280": { "content": "<|dummy_16|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100281": { "content": "<|dummy_17|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100282": { "content": "<|dummy_18|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100283": { "content": "<|dummy_19|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100284": { "content": "<|dummy_20|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100285": { "content": "<|dummy_21|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100286": { "content": "<|dummy_22|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100287": { "content": "<|dummy_23|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100288": { "content": "<|dummy_24|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100289": { "content": "<|dummy_25|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100290": { "content": "<|dummy_26|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100291": { "content": "<|dummy_27|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100292": { "content": "<|dummy_28|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100293": { "content": "<|dummy_29|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100294": { "content": "<|dummy_30|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100295": { "content": "<|dummy_31|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100296": { "content": "<|dummy_32|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100297": { "content": "<|dummy_33|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100298": { "content": "<|dummy_34|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100299": { "content": "<|dummy_35|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100300": { "content": "<|dummy_36|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100301": { "content": "<|dummy_37|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100302": { "content": "<|dummy_38|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100303": { "content": "<|dummy_39|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100304": { "content": "<|dummy_40|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100305": { "content": "<|dummy_41|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100306": { "content": "<|dummy_42|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100307": { "content": "<|dummy_43|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100308": { "content": "<|dummy_44|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100309": { "content": "<|dummy_45|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100310": { "content": "<|dummy_46|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100311": { "content": "<|dummy_47|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100312": { "content": "<|dummy_48|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100313": { "content": "<|dummy_49|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100314": { "content": "<|dummy_50|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100315": { "content": "<|dummy_51|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100316": { "content": "<|dummy_52|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100317": { "content": "<|dummy_53|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100318": { "content": "<|dummy_54|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100319": { "content": "<|dummy_55|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100320": { "content": "<|dummy_56|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100321": { "content": "<|dummy_57|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100322": { "content": "<|dummy_58|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100323": { "content": "<|dummy_59|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100324": { "content": "<|dummy_60|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100325": { "content": "<|dummy_61|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100326": { "content": "<|dummy_62|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100327": { "content": "<|dummy_63|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100328": { "content": "<|dummy_64|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100329": { "content": "<|dummy_65|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100330": { "content": "<|dummy_66|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100331": { "content": "<|dummy_67|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100332": { "content": "<|dummy_68|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100333": { "content": "<|dummy_69|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100334": { "content": "<|dummy_70|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100335": { "content": "<|dummy_71|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100336": { "content": "<|dummy_72|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100337": { "content": "<|dummy_73|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100338": { "content": "<|dummy_74|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100339": { "content": "<|dummy_75|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100340": { "content": "<|dummy_76|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100341": { "content": "<|dummy_77|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100342": { "content": "<|dummy_78|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100343": { "content": "<|dummy_79|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100344": { "content": "<|dummy_80|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100345": { "content": "<|dummy_81|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100346": { "content": "<|dummy_82|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100347": { "content": "<|dummy_83|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100348": { "content": "<|dummy_84|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100349": { "content": "<|dummy_85|>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": true }, "100350": { "content": "<think>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": false }, "100351": { "content": "</think>", "lstrip": true, "normalized": false, "rstrip": true, "single_word": false, "special": false } }, "bos_token": "<|endoftext|>", "chat_template": "<|im_start|>system<|im_sep|>You are Phi, a language model trained by Microsoft to help users. Your role as an assistant involves thoroughly exploring questions through a systematic thinking process before providing the final precise and accurate solutions. This requires engaging in a comprehensive cycle of analysis, summarizing, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. Please structure your response into two main sections: Thought and Solution using the specified format: <think> {Thought section} </think> {Solution section}. In the Thought section, detail your reasoning process in steps. Each step should include detailed considerations such as analysing questions, summarizing relevant findings, brainstorming new ideas, verifying the accuracy of the current steps, refining any errors, and revisiting previous steps. In the Solution section, based on various attempts, explorations, and reflections from the Thought section, systematically present the final solution that you deem correct. The Solution section should be logical, accurate, and concise and detail necessary steps needed to reach the conclusion. Now, try to solve the following question through the above guidelines:<|im_end|>{% for message in messages %}{% if (message['role'] == 'user') %}{{'<|im_start|>user<|im_sep|>' + message['content'] + '<|im_end|>'}}{% elif (message['role'] == 'assistant') %}{{'<|im_start|>assistant<|im_sep|>'}}{% generation %}{{message['content'] + '<|im_end|>'}}{% endgeneration %}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant<|im_sep|>' }}{% endif %}", "clean_up_tokenization_spaces": false, "eos_token": "<|im_end|>", "extra_special_tokens": {}, "model_max_length": 32768, "pad_token": "<|dummy_85|>", "padding_side": "left", "tokenizer_class": "GPT2Tokenizer"}CODE_OF_CONDUCT.mdAdded+9
LICENSEAdded+22
README.mdAdded+218
SECURITY.mdAdded+41
added_tokens.jsonAdded+13
auth.htmlAdded+1510
chat.htmlAdded+1177
config.jsonAdded+32
data_summary_card.mdAdded+149
file_pipeline.pyAdded+397
generate.pyAdded+55
generation_config.jsonAdded+11
load_model.pyAdded+48
model-00001-of-00006.safetensorsAdded+3
model-00002-of-00006.safetensorsAdded+3
model-00003-of-00006.safetensorsAdded+3
model-00004-of-00006.safetensorsAdded+3
model-00005-of-00006.safetensorsAdded+3
model-00006-of-00006.safetensorsAdded+3
model.safetensors.index.jsonAdded+250
requirements.txtAdded+21
run.pyAdded+221
sample_finetune.pyAdded+214
special_tokens_map.jsonAdded+23
tokenizer.jsonAdded
tokenizer.modelAdded+3
tokenizer_config.jsonAdded+782
vocab.jsonAdded