Athagi commited on
Commit
603570b
·
verified ·
1 Parent(s): 8a1d75e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
+ import gradio as gr
4
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
5
+ import torch
6
+
7
+ # Load the model and tokenizer from Hugging Face
8
+ model_path = "Athagi/Agillm-v2" # Model loaded from Hugging Face Hub
9
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
10
+ model = AutoModelForCausalLM.from_pretrained(model_path)
11
+
12
+ # Create a text generation pipeline
13
+ chatbot = pipeline("text-generation", model=model, tokenizer=tokenizer, device=0 if torch.cuda.is_available() else -1)
14
+
15
+ # Function to generate response
16
+ def chat_with_model(user_input):
17
+ response = chatbot(user_input, max_length=200, do_sample=True, temperature=0.7)
18
+ return response[0]['generated_text']
19
+
20
+ # Gradio interface
21
+ interface = gr.Interface(
22
+ fn=chat_with_model, # Function to generate the response
23
+ inputs="text", # Input: Text box for user input
24
+ outputs="text", # Output: Generated response
25
+ title="Chat with Agillm-v2", # Title of the app
26
+ description="Type a message and interact with the Agillm-v2 model.",
27
+ theme="huggingface" # Optional: Use Hugging Face theme
28
+ )
29
+
30
+ # Launch the app
31
+ interface.launch()