dammy commited on
Commit
6296560
1 Parent(s): 65ed9df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py CHANGED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import transformers
3
+
4
+ # Load a pre-trained model.
5
+ model = transformers.AutoModelForSeq2SeqLM.from_pretrained("facebook/bart-large")
6
+
7
+ # Define a function to generate text.
8
+ def generate_text(text):
9
+ """Generates text based on a given prompt."""
10
+
11
+ # Tokenize the input text.
12
+ input_ids = model.tokenizer.encode(text, return_tensors="pt")
13
+
14
+ # Generate text.
15
+ output_ids = model.generate(input_ids=input_ids, max_length=100, num_beams=5)
16
+
17
+ # Decode the output text.
18
+ output_text = model.tokenizer.decode(output_ids[0])
19
+
20
+ return output_text
21
+
22
+ # Define the Gradio interface.
23
+ chat_box = gr.inputs.Textbox(label="Chat Box")
24
+ chat_button = gr.Button("Send")
25
+ chat_response = gr.outputs.Textbox(label="Chat Response")
26
+
27
+ # Connect the inputs and outputs to the generate_text function.
28
+ chat_button.click(generate_text, chat_box, chat_response)
29
+
30
+ # Launch the Gradio interface.
31
+ interface = gr.Interface([chat_box, chat_button], [chat_response])
32
+ interface.launch()