tdnathmlenthusiast commited on
Commit
715b816
1 Parent(s): 27c7519

actual code deployed

Browse files
Files changed (1) hide show
  1. app.py +31 -22
app.py CHANGED
@@ -1,26 +1,35 @@
 
 
 
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
- import torch
4
-
5
- # Initialize the tokenizer and model
6
- tokenizer = AutoTokenizer.from_pretrained("laptop_data.pkl")
7
- model = AutoModelForSequenceClassification.from_pretrained("laptop_data.pkl")
8
-
9
- # Define the function for classifying laptops
10
- def classify_laptop(description):
11
- inputs = tokenizer(description, return_tensors="pt", padding=True, truncation=True)
12
- outputs = model(**inputs)
13
- logits = outputs.logits
14
- probabilities = torch.softmax(logits, dim=1)
15
- return {label: prob.item() for label, prob in zip(model.config.id2label.values(), probabilities[0])}
16
-
17
- # Create the Gradio interface
 
 
 
18
  iface = gr.Interface(
19
- fn=classify_laptop,
20
- inputs=gr.inputs.Textboxbox(),
21
- outputs=gr.outputs.Label(num_top_classes=5),
22
- live=True
 
 
 
23
  )
24
 
25
- # Launch the Gradio interface
26
- iface.launch()
 
1
+
2
+
3
+ # Import necessary libraries
4
  import gradio as gr
5
+ from pathlib import Path
6
+ from fastai.text.all import *
7
+ from blurr.text.data.all import *
8
+ from blurr.text.modeling.all import *
9
+ import pathlib
10
+
11
+ # Load the learner
12
+ inf_learn = load_learner(fname=Path("laptop_summarizer_1.pkl"))
13
+
14
+ # Define a function to generate summaries using your model
15
+
16
+
17
+ def generate_summary(input_text):
18
+ prediction = inf_learn.blurr_generate(input_text)
19
+ generated_text = prediction[0]['generated_texts']
20
+ return generated_text
21
+
22
+
23
+ # Create an interface for the model
24
  iface = gr.Interface(
25
+ fn=generate_summary, # The function to generate summaries
26
+ inputs=gr.inputs.Textbox(), # Input field for text
27
+ outputs=gr.outputs.Textbox(), # Output field for generated text
28
+ live=True, # Whether to update results in real-time
29
+ title="Laptop Guru", # Title of the interface
30
+ # Description of the interface
31
+ description="Enter your requirements & get valuable insight from Guru."
32
  )
33
 
34
+ # Start the Gradio app
35
+ iface.launch(inline=False)