tbelvin5969 commited on
Commit
02c8082
·
verified ·
1 Parent(s): ff3f23a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -7
app.py CHANGED
@@ -1,13 +1,28 @@
1
  import gradio as gr
2
- from transformers import pipeline
 
3
 
4
- # Load model
5
  model_name = "Genius-Society/insecta"
6
- insecta_pipeline = pipeline("text-generation", model=model_name)
 
7
 
 
8
  def generate_response(prompt):
9
- return insecta_pipeline(prompt, max_length=100)[0]['generated_text']
 
 
10
 
11
- # Gradio interface
12
- iface = gr.Interface(fn=generate_response, inputs="text", outputs="text")
13
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import torch
3
+ from transformers import AutoModel, AutoTokenizer
4
 
5
+ # Load model and tokenizer
6
  model_name = "Genius-Society/insecta"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModel.from_pretrained(model_name)
9
 
10
+ # Define inference function
11
  def generate_response(prompt):
12
+ inputs = tokenizer(prompt, return_tensors="pt") # Tokenize input text
13
+ with torch.no_grad(): # Disable gradients for inference
14
+ output = model(**inputs)
15
 
16
+ return str(output) # Convert output to string for display
17
+
18
+ # Create Gradio interface
19
+ iface = gr.Interface(
20
+ fn=generate_response,
21
+ inputs="text",
22
+ outputs="text",
23
+ title="Insecta AI Model",
24
+ description="Generate responses using Genius-Society/Insecta hosted on Hugging Face Spaces."
25
+ )
26
+
27
+ if __name__ == "__main__":
28
+ iface.launch()