DisgustingOzil commited on
Commit
9a3b152
1 Parent(s): 366a093

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +55 -13
README.md CHANGED
@@ -32,44 +32,86 @@ import gradio as gr
32
  from transformers import AutoTokenizer
33
  from peft import AutoPeftModelForCausalLM
34
  import torch
 
35
 
36
- # Assuming the model and tokenizer are correctly set up as per your provided code.
37
- def summarize_text(text):
38
- load_in_4bit = True
39
- model = AutoPeftModelForCausalLM.from_pretrained(
40
  "DisgustingOzil/Mistral_summarizer",
41
  load_in_4bit=load_in_4bit,
42
  torch_dtype=torch.float16,
43
  ).to("cuda")
44
- tokenizer = AutoTokenizer.from_pretrained("DisgustingOzil/Mistral_summarizer")
45
-
 
 
46
  summary_prompt = f"""Below is a text that needs to be summarized. Based on the input, write a good summary which summarize all main points.
47
 
48
  ### Text:
49
  {text}
50
 
51
  ### Summary:
52
- """ # The summary part is left empty for generation
53
 
54
  inputs = tokenizer([summary_prompt], return_tensors="pt").to("cuda")
55
- outputs = model.generate(**inputs, max_new_tokens=200, use_cache=True)
56
  summary = tokenizer.batch_decode(outputs, skip_special_tokens=True)
57
  summary_start_index = summary[0].find("### Summary:")
58
  summary_text = summary[0][summary_start_index:].replace("### Summary:", "").strip()
59
  return summary_text
60
-
61
- # Define the Gradio interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  iface = gr.Interface(
63
  fn=summarize_text,
64
- inputs=gr.Textbox(lines=10, label="Input Text"),
65
  outputs=gr.Textbox(label="Summary"),
66
  title="Text Summarization",
67
- description="Enter text to summarize based on Maxwell's equations and related concepts."
68
  )
69
 
70
  # Launch the app
71
  if __name__ == "__main__":
72
- iface.launch()
 
73
 
74
 
75
 
 
32
  from transformers import AutoTokenizer
33
  from peft import AutoPeftModelForCausalLM
34
  import torch
35
+ import anthropic
36
 
37
+ # Assuming the model and tokenizer for Mistral are correctly set up as per your provided code.
38
+ # Let's also assume you have a way to call the Anthropic model, perhaps via an API or another library.
39
+ load_in_4bit = True
40
+ model = AutoPeftModelForCausalLM.from_pretrained(
41
  "DisgustingOzil/Mistral_summarizer",
42
  load_in_4bit=load_in_4bit,
43
  torch_dtype=torch.float16,
44
  ).to("cuda")
45
+ tokenizer = AutoTokenizer.from_pretrained("DisgustingOzil/Mistral_summarizer")
46
+ def summarize_with_mistral(text):
47
+
48
+
49
  summary_prompt = f"""Below is a text that needs to be summarized. Based on the input, write a good summary which summarize all main points.
50
 
51
  ### Text:
52
  {text}
53
 
54
  ### Summary:
55
+ """ # The summary part is left empty for generation
56
 
57
  inputs = tokenizer([summary_prompt], return_tensors="pt").to("cuda")
58
+ outputs = model.generate(**inputs, max_new_tokens=150, use_cache=True)
59
  summary = tokenizer.batch_decode(outputs, skip_special_tokens=True)
60
  summary_start_index = summary[0].find("### Summary:")
61
  summary_text = summary[0][summary_start_index:].replace("### Summary:", "").strip()
62
  return summary_text
63
+ summary_1=""
64
+ def summarize_with_anthropic(text):
65
+ API_KEY="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"
66
+
67
+ client = anthropic.Anthropic(
68
+ # defaults to os.environ.get("ANTHROPIC_API_KEY")
69
+ api_key=API_KEY,
70
+ )
71
+ message = client.messages.create(
72
+ model="claude-3-haiku-20240307",
73
+ max_tokens=3214,
74
+ temperature=0,
75
+ system="Create Good summary explaining all key points in detail, easy and understandable way",
76
+ messages=[
77
+ {
78
+ "role": "user",
79
+ "content": [
80
+ {
81
+ "type": "text",
82
+ "text": text
83
+ }
84
+ ]
85
+ }
86
+ ]
87
+ )
88
+ # Placeholder function to represent summarization with an Anthropic model.
89
+ # This should be replaced with actual API calls or function calls to the Anthropic model.
90
+ # summary_1=message.content[0]
91
+ summary=message.content[0]
92
+ return summary.text
93
+
94
+ def summarize_text(text, model_choice):
95
+ if model_choice == "Mistral 7b":
96
+ return summarize_with_mistral(text)
97
+ elif model_choice == "Claude-3-Haiku":
98
+ return summarize_with_anthropic(text)
99
+ else:
100
+ return "Invalid model choice."
101
+
102
+ # Define the Gradio interface with a dropdown for model selection
103
  iface = gr.Interface(
104
  fn=summarize_text,
105
+ inputs=[gr.Textbox(lines=10, label="Input Text"), gr.Dropdown(choices=["Mistral 7b", "Claude-3-Haiku"], label="Model Choice")],
106
  outputs=gr.Textbox(label="Summary"),
107
  title="Text Summarization",
108
+ description="Enter text to summarize based on Maxwell's equations and related concepts. Select a model for summarization."
109
  )
110
 
111
  # Launch the app
112
  if __name__ == "__main__":
113
+ iface.launch(debug=True)
114
+
115
 
116
 
117