Daniton commited on
Commit
d4a30d1
Β·
1 Parent(s): a086b47

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline, set_seed
3
+
4
+ # Load the h2oai/h2ogpt-oasst1-512-20b model from Hugging Face
5
+ generator = pipeline('text-generation', model='h2oai/h2ogpt-oasst1-512-20b', device=0)
6
+
7
+ # Set the seed for the model to ensure consistent results
8
+ set_seed(42)
9
+
10
+ # Define the chatbot function
11
+ def chatbot(input_text):
12
+ # Generate a response from the model given the input text
13
+ output_text = generator(input_text, max_length=100)[0]['generated_text']
14
+ # Return the generated response
15
+ return output_text.strip()
16
+
17
+ # Create a Gradio interface for the chatbot
18
+ interface = gr.Interface(
19
+ fn=chatbot,
20
+ inputs=gr.inputs.Textbox(lines=2, label="Input Text"),
21
+ outputs=gr.outputs.Textbox(label="Generated Text")
22
+ )
23
+
24
+ # Launch the interface
25
+ interface.launch()