Simonsbs commited on
Commit
318fc31
·
1 Parent(s): f2b15c9

Refactor model loading and response generation in app.py; update requirements.txt

Browse files
Files changed (2) hide show
  1. app.py +9 -10
  2. requirements.txt +0 -0
app.py CHANGED
@@ -1,19 +1,18 @@
1
- import os
2
  import gradio as gr
3
- from huggingface_hub import hf_hub_download
4
- from ctransformers import AutoModelForCausalLM
5
 
6
- # Download the model
7
- repo_id = "TheBloke/zephyr-7b-beta-GGUF"
8
- filename = "zephyr-7b-beta.Q4_K_S.gguf"
9
- model_path = hf_hub_download(repo_id=repo_id, filename=filename)
10
 
11
- # Load the model
12
- llm = AutoModelForCausalLM.from_pretrained(model_path, model_type='llama')
13
 
14
  # Define the response function
15
  def respond(prompt):
16
- return llm(prompt)
 
17
 
18
  # Create the Gradio interface
19
  iface = gr.Interface(fn=respond, inputs="text", outputs="text", title="SimonGPT")
 
 
1
  import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
 
3
 
4
+ # Load the tokenizer and model
5
+ model_name = "HuggingFaceTB/SmolLM2-360M-Instruct"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
8
 
9
+ # Create a text-generation pipeline
10
+ generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
11
 
12
  # Define the response function
13
  def respond(prompt):
14
+ response = generator(prompt, max_length=512, do_sample=True, temperature=0.7)
15
+ return response[0]["generated_text"]
16
 
17
  # Create the Gradio interface
18
  iface = gr.Interface(fn=respond, inputs="text", outputs="text", title="SimonGPT")
requirements.txt CHANGED
Binary files a/requirements.txt and b/requirements.txt differ