GaborToth2 commited on
Commit
6ea52a1
·
1 Parent(s): e7a6ee0

secret set on HF

Browse files
Files changed (3) hide show
  1. app.py +6 -6
  2. asd.py → gradio_local.py +0 -0
  3. model_local.py +19 -0
app.py CHANGED
@@ -1,11 +1,11 @@
1
- import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- """
5
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
- """
7
  models = ["HuggingFaceH4/zephyr-7b-beta", "microsoft/Phi-4-mini-instruct"]
8
- client = InferenceClient(model=models[1])
 
9
 
10
 
11
  def respond(
@@ -16,7 +16,7 @@ def respond(
16
  temperature,
17
  top_p,
18
  ):
19
- messages = [{"role": "system", "content": system_message}]
20
 
21
  for val in history:
22
  if val[0]:
 
1
+ import os
2
  from huggingface_hub import InferenceClient
3
 
4
+ HF_API_KEY = os.getenv("HF_API_KEY") # Retrieve API key from environment variable
5
+
 
6
  models = ["HuggingFaceH4/zephyr-7b-beta", "microsoft/Phi-4-mini-instruct"]
7
+ client = InferenceClient(model=models[1], token=HF_API_KEY) # Pass API key to client
8
+
9
 
10
 
11
  def respond(
 
16
  temperature,
17
  top_p,
18
  ):
19
+ = [{"role": "system", "content": system_message}]
20
 
21
  for val in history:
22
  if val[0]:
asd.py → gradio_local.py RENAMED
File without changes
model_local.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer
2
+ import torch
3
+
4
+ model_name = "microsoft/Phi-4-mini-instruct"
5
+
6
+ # Load model and tokenizer
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
9
+
10
+ # Generate a response
11
+ def chat_with_model(prompt, max_new_tokens=100):
12
+ inputs = tokenizer(prompt, return_tensors="pt").to("cpu") # Move to GPU if available
13
+ output = model.generate(**inputs, max_new_tokens=max_new_tokens)
14
+ return tokenizer.decode(output[0], skip_special_tokens=True)
15
+
16
+ # Test the model
17
+ user_input = "Explain quantum computing in simple terms."
18
+ response = chat_with_model(user_input)
19
+ print("Chatbot Response:", response)