Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
|
4 |
+
# Load a pretrained AI model (Mistral-7B or any Hugging Face model)
|
5 |
+
model_name = "mistralai/Mistral-7B-Instruct-v0.1"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
|
8 |
+
|
9 |
+
# AI Chatbot function
|
10 |
+
def chat_with_ai(prompt):
|
11 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
12 |
+
outputs = model.generate(**inputs, max_new_tokens=100)
|
13 |
+
return tokenizer.decode(outputs[0])
|
14 |
+
|
15 |
+
# Create a simple chatbot UI using Gradio
|
16 |
+
interface = gr.Interface(fn=chat_with_ai, inputs="text", outputs="text", title="AI Chatbot")
|
17 |
+
interface.launch()
|