Spaces:
Sleeping
Sleeping
Download app.py from Chuxia-sys/new_phi3: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/spaces/Chuxia-sys/new_phi3/resolve/main/app.py
- Command line
-
hf download hf://spaces/Chuxia-sys/new_phi3/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Chuxia-sys/new_phi3/resolve/main/app.py
1.34 kB
| import gradio as gr | |
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| import torch | |
| # --- Load model and tokenizer --- | |
| model_name = "Chuxia-sys/phi3-travel-merged" # your merged model repo | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_name, | |
| torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32, | |
| device_map="auto" | |
| ) | |
| # --- Define generation function --- | |
| def generate_response(prompt): | |
| inputs = tokenizer(prompt, return_tensors="pt").to(model.device) | |
| outputs = model.generate( | |
| **inputs, | |
| max_new_tokens=300, | |
| temperature=0.7, | |
| top_p=0.9, | |
| do_sample=True, | |
| pad_token_id=tokenizer.eos_token_id | |
| ) | |
| response = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| return response | |
| # --- Create Gradio interface --- | |
| demo = gr.Interface( | |
| fn=generate_response, | |
| inputs=gr.Textbox(label="Enter your travel query", placeholder="Example: Create a 3-day travel plan to Batangas with ₱7000 budget"), | |
| outputs=gr.Textbox(label="AI Travel Plan"), | |
| title="🌏 Phi3 Travel Planner API", | |
| description="A travel planning AI model that generates itineraries and travel suggestions using your fine-tuned model." | |
| ) | |
| # --- Launch --- | |
| if __name__ == "__main__": | |
| demo.launch() | |