Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,35 @@
|
|
| 1 |
-
import requests
|
| 2 |
-
import json
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
'Content-Type':'application/json'
|
| 10 |
-
}
|
| 11 |
-
|
| 12 |
-
history=[]
|
| 13 |
|
| 14 |
def generate_response(prompt):
|
| 15 |
history.append(prompt)
|
| 16 |
-
final_prompt="\n".join(history)
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
)
|
| 40 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
|
| 4 |
+
# Load your text generation model from Hugging Face using its identifier
|
| 5 |
+
model_identifier = "curiouscurrent/omnicode"
|
| 6 |
+
model = AutoModelForCausalLM.from_pretrained(model_identifier)
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_identifier)
|
| 8 |
|
| 9 |
+
history = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def generate_response(prompt):
|
| 12 |
history.append(prompt)
|
| 13 |
+
final_prompt = "\n".join(history)
|
| 14 |
+
|
| 15 |
+
# Tokenize input prompt
|
| 16 |
+
input_ids = tokenizer.encode(final_prompt, return_tensors="pt", max_length=512, truncation=True)
|
| 17 |
+
|
| 18 |
+
# Generate response
|
| 19 |
+
output_ids = model.generate(input_ids, max_length=100, num_return_sequences=1)
|
| 20 |
+
response = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 21 |
+
|
| 22 |
+
return response
|
| 23 |
+
|
| 24 |
+
# Create Gradio interface
|
| 25 |
+
input_prompt = gr.inputs.Textbox(lines=4, label="Input Prompt")
|
| 26 |
+
output_text = gr.outputs.Textbox(label="Response")
|
| 27 |
+
|
| 28 |
+
gr.Interface(
|
| 29 |
+
generate_response,
|
| 30 |
+
inputs=input_prompt,
|
| 31 |
+
outputs=output_text,
|
| 32 |
+
title="OmniCode",
|
| 33 |
+
description="Multi programming coding assistant",
|
| 34 |
+
theme="compact"
|
| 35 |
+
).launch()
|
|
|
|
|
|