Raiff1982 commited on
Commit
e513d6a
·
verified ·
1 Parent(s): e082d82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -4
app.py CHANGED
@@ -1,7 +1,38 @@
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, set_seed
3
 
4
+ # Load Hugging Face model (adjust as needed)
5
+ generator = pipeline("text-generation", model="gpt2")
6
+ set_seed(42)
7
 
8
+ chat_history = []
9
+
10
+ # Text generation function
11
+ def codette_terminal(user_input):
12
+ global chat_history
13
+ if user_input.lower() in ["exit", "quit"]:
14
+ chat_history = []
15
+ return "🧠 Codette signing off. Type again to restart."
16
+
17
+ output = generator(user_input, max_length=100, num_return_sequences=1)
18
+ response = output[0]['generated_text'].strip()
19
+
20
+ # Update terminal-style chat log
21
+ chat_history.append(f"🖋️ You > {user_input}")
22
+ chat_history.append(f"🧠 Codette > {response}")
23
+ return "\n".join(chat_history[-10:]) # Keep last 10 entries for brevity
24
+
25
+ # Gradio Interface
26
+ with gr.Blocks(title="Codette Terminal") as demo:
27
+ gr.Markdown("## 🧬 Codette Terminal Interface (Hugging Face Edition)")
28
+ gr.Markdown("Type your message below. Type `'exit'` to reset conversation.\n")
29
+
30
+ with gr.Row():
31
+ input_box = gr.Textbox(label="Your input", placeholder="Ask me anything...", lines=1)
32
+ output_box = gr.Textbox(label="Codette Output", lines=15, interactive=False)
33
+
34
+ input_box.submit(fn=codette_terminal, inputs=input_box, outputs=output_box)
35
+
36
+ # Launch in HF Space
37
+ if __name__ == "__main__":
38
+ demo.launch()