Refactor model loading and response generation in app.py; update requirements.txt
Browse files- app.py +9 -10
- requirements.txt +0 -0
app.py
CHANGED
|
@@ -1,19 +1,18 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
from
|
| 4 |
-
from ctransformers import AutoModelForCausalLM
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
|
| 14 |
# Define the response function
|
| 15 |
def respond(prompt):
|
| 16 |
-
|
|
|
|
| 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
|
|
|