PuruAI commited on
Commit
10d74c7
·
verified ·
1 Parent(s): e69b959

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -26
app.py CHANGED
@@ -1,34 +1,23 @@
1
  import os
2
- from transformers import pipeline
3
 
4
- # ✅ Set Hugging Face token (replace with your token)
5
- # Option 1: Directly in script (works locally)
6
- os.environ["HUGGINGFACE_HUB_TOKEN"] = "YOUR_HUGGINGFACE_TOKEN_HERE"
7
 
8
- # Option 2: If running in a container, make sure HUGGINGFACE_HUB_TOKEN
9
- # is set as an environment variable externally (Docker, cloud, etc.)
10
 
11
- # Model names
12
- MEDINI_MODEL = "PuruAI/Medini_Intelligence"
13
  FALLBACK_MODEL = "gpt2"
14
 
15
- # Function to safely load a model
16
- def load_model(model_name, fallback_model):
17
- try:
18
- print(f"Loading model: {model_name}")
19
- generator = pipeline("text-generation", model=model_name)
20
- print(" Model loaded successfully!")
21
- return generator
22
- except Exception as e:
23
- print(f"⚠️ Failed to load {model_name}: {e}")
24
- print(f"⏩ Falling back to {fallback_model}")
25
- generator = pipeline("text-generation", model=fallback_model)
26
- return generator
27
-
28
- # Load Medini model or fallback
29
- generator = load_model(MEDINI_MODEL, FALLBACK_MODEL)
30
 
31
- # Example usage
32
- prompt = "Hello Medini AI, can you explain AI agents?"
33
- result = generator(prompt, max_length=100, do_sample=True)
34
  print(result)
 
1
  import os
 
2
 
3
+ # ✅ Set your Hugging Face token before any Hugging Face imports
4
+ os.environ["HUGGINGFACE_HUB_TOKEN"] = "YOUR_HUGGINGFACE_TOKEN" # Replace with your actual token
 
5
 
6
+ from transformers import pipeline
 
7
 
8
+ # Model configuration
9
+ MODEL_ID = "PuruAI/Medini_Intelligence"
10
  FALLBACK_MODEL = "gpt2"
11
 
12
+ # Try loading your main model
13
+ try:
14
+ generator = pipeline("text-generation", model=MODEL_ID)
15
+ print(" Medini_AI loaded successfully!")
16
+ except Exception as e:
17
+ print(f"⚠️ Failed to load Medini_AI: {e}")
18
+ print("⏩ Falling back to GPT-2...")
19
+ generator = pipeline("text-generation", model=FALLBACK_MODEL)
 
 
 
 
 
 
 
20
 
21
+ # Test the pipeline
22
+ result = generator("Hello world!", max_length=50)
 
23
  print(result)