Spaces:
No application file
No application file
Create Main.py
Browse files
Main.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
# Load the DialoGPT-medium model and tokenizer (renamed to 1111)
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
|
| 6 |
+
model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")
|
| 7 |
+
|
| 8 |
+
# Function for generating responses (renamed as 1111)
|
| 9 |
+
def chat_with_1111(input_text):
|
| 10 |
+
# Encode the input text using the tokenizer
|
| 11 |
+
input_ids = tokenizer.encode(input_text + tokenizer.eos_token, return_tensors='pt')
|
| 12 |
+
|
| 13 |
+
# Generate a response using the model (1111)
|
| 14 |
+
chat_history_ids = model.generate(input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id)
|
| 15 |
+
|
| 16 |
+
# Decode and return the response
|
| 17 |
+
response = tokenizer.decode(chat_history_ids[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
|
| 18 |
+
return response
|
| 19 |
+
|
| 20 |
+
# Define the Gradio interface
|
| 21 |
+
iface = gr.Interface(fn=chat_with_1111,
|
| 22 |
+
inputs=gr.Textbox(lines=2, placeholder="Ask 1111 a question..."),
|
| 23 |
+
outputs="text",
|
| 24 |
+
live=True,
|
| 25 |
+
title="Chat with 1111",
|
| 26 |
+
description="Talk to 1111, an AI trained with DialoGPT medium!")
|
| 27 |
+
|
| 28 |
+
# Launch the interface (This will run on Aifaces when uploaded)
|
| 29 |
+
iface.launch()
|