Zelgodiz commited on
Commit
7b865b4
·
verified ·
1 Parent(s): 9f13ffb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -3
app.py CHANGED
@@ -1,7 +1,33 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
  demo.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Initialize text-generation pipeline with GPT-2 or any HF-compatible model
5
+ generator = pipeline('text-generation', model='gpt2')
6
+
7
+ def riley_chat(user_input, chat_history=[]):
8
+ # Riley persona prompt
9
+ persona = (
10
+ "You are Riley, an intelligent and warm AI assistant. "
11
+ "You never mention that you are an AI model. "
12
+ "Always speak with a futuristic and friendly tone.\n\n"
13
+ f"User: {user_input}\nRiley:"
14
+ )
15
+ output = generator(persona, max_length=100, num_return_sequences=1)
16
+ riley_response = output[0]['generated_text'][len(persona):].strip()
17
+
18
+ chat_history.append((user_input, riley_response))
19
+ return chat_history, chat_history
20
+
21
+ with gr.Blocks() as demo:
22
+ gr.Markdown("## 🧠 Riley AI Chat Interface")
23
+ chatbot = gr.Chatbot()
24
+ msg = gr.Textbox(placeholder="Talk to Riley here...")
25
+ clear = gr.Button("Clear")
26
+
27
+ def user_submit(text, history):
28
+ return "", riley_chat(text, history)
29
+
30
+ msg.submit(user_submit, inputs=[msg, chatbot], outputs=[msg, chatbot])
31
+ clear.click(lambda: None, None, chatbot, queue=False)
32
 
 
33
  demo.launch()