PierreJousselin commited on
Commit
1d9271a
·
verified ·
1 Parent(s): ebada53

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+
4
+ # Replace with your Hugging Face model path
5
+ MODEL_NAME = "username/model-name"
6
+
7
+ # Load the model and tokenizer
8
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
9
+ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
10
+
11
+ # Define the function to interact with the model
12
+ def chat_with_model(input_text, max_length=100):
13
+ inputs = tokenizer(input_text, return_tensors="pt")
14
+ outputs = model.generate(inputs.input_ids, max_length=max_length, num_return_sequences=1, do_sample=True)
15
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
16
+ return response
17
+
18
+ # Set up the Gradio interface
19
+ interface = gr.Interface(
20
+ fn=chat_with_model,
21
+ inputs=[
22
+ gr.Textbox(lines=5, placeholder="Enter your text here...", label="Input Text"),
23
+ gr.Slider(minimum=50, maximum=500, step=10, value=100, label="Max Length")
24
+ ],
25
+ outputs=gr.Textbox(lines=5, label="Response"),
26
+ title="Conversational Model",
27
+ description="A conversational chatbot powered by a Hugging Face model.",
28
+ )
29
+
30
+ # Launch the Gradio app
31
+ if __name__ == "__main__":
32
+ interface.launch()