Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,38 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|