Keyven commited on
Commit
36be628
·
1 Parent(s): bb8d3ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -1,16 +1,27 @@
 
1
  import gradio as gr
 
 
 
 
 
2
 
3
  def chat_with_kiki_gpt(user_input):
4
- return f"KIKI-GPT: {user_input}"
 
 
 
 
 
5
 
 
6
  interface = gr.Interface(
7
- fn=chat_with_kiki_gpt,
8
  inputs=gr.inputs.Textbox(lines=5, placeholder="Type your message to KIKI-GPT here..."),
9
  outputs=gr.outputs.Textbox(),
10
  title="KIKI-GPT",
11
- description="Welcome to KIKI-GPT - a project on HuggingFace Spaces using Microsoft's DialoGPT. One of the fastest and best performing models for robotics! Created by Keyvan Hardani. For inquiries, contact: [email protected].",
12
- live=True
13
  )
14
 
15
- interface.load("models/microsoft/DialoGPT-medium")
16
  interface.launch()
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer
2
  import gradio as gr
3
+ import torch
4
+
5
+ # DialoGPT Modell und Tokenizer laden
6
+ tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
7
+ model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")
8
 
9
  def chat_with_kiki_gpt(user_input):
10
+ # Benutzereingabe kodieren und Modellantwort generieren
11
+ input_ids = tokenizer.encode(user_input + tokenizer.eos_token, return_tensors='pt')
12
+ chat_history_ids = model.generate(input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id)
13
+ chat_output = tokenizer.decode(chat_history_ids[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
14
+
15
+ return f"KIKI-GPT: {chat_output}"
16
 
17
+ # Gradio-Benutzeroberfläche
18
  interface = gr.Interface(
19
+ fn=chat_with_kiki_gpt,
20
  inputs=gr.inputs.Textbox(lines=5, placeholder="Type your message to KIKI-GPT here..."),
21
  outputs=gr.outputs.Textbox(),
22
  title="KIKI-GPT",
23
+ description="Welcome to KIKI-GPT - a project on Hugging Face Spaces using Microsoft's DialoGPT. One of the fastest and best performing models for robotics! Created by Keyvan Hardani. For inquiries, contact: [email protected].",
24
+ live=True
25
  )
26
 
 
27
  interface.launch()